wasim
wasim

Reputation: 708

how to solve strange behavior of ui tab bar in ios 7

I am creating an application in which I am using the tab bar with 3 tabs. Everything works fine in iOS 6, but in iOS 7 when I click on tab 3 it checks if user is logged in or not.

-(void)viewWillAppear:(BOOL)animated
{
     appdelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
     appdelegate.strLoginMessage=@"setting";
     BOOL isLogin= [[[NSUserDefaults standardUserDefaults] objectForKey:@"isLogin"]intValue ];
     if (isLogin) 
     {
         [self webService_Count];
     }
     else
     {
         appdelegate.showLoginBack=NO;
         ViewController *view=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
         [self.navigationController pushViewController:view animated:YES];
    }
}

If user is not login then i send it to the login page. But from here if user taps on the tab 3 it go to setting page without login. And if user again clicks tab 3 it shows black screen. I can't understand why?

This is how I setup my tab bar in appDelegate

self.nav= [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.nav1=[[UINavigationController alloc]initWithRootViewController:self.messageviewcontroller];
self.nav2=[[UINavigationController alloc]initWithRootViewController:self.settingviewController];

in nav1 and nav2 i check if the user login or not in view will appear.

Upvotes: 0

Views: 288

Answers (3)

wasim
wasim

Reputation: 708

following solve my problem.i changes the root view after login and assiged the login page as root view at logout time.

 ViewController *view=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
            [self.navigationController setViewControllers:[NSArray arrayWithObject:view] animated:YES];

            MessageLoginViewController *message=[[MessageLoginViewController alloc]initWithNibName:@"MessageLoginViewController" bundle:nil];
            [appdelegate.nav1 setViewControllers:[NSArray arrayWithObject:message]];

Upvotes: 1

Son Nguyen
Son Nguyen

Reputation: 3491

You should check if user is not login then show login screen as a root view instead of push it into current navigation controller:

ViewController *view = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
appDelegate.window.rootViewController = view;

Upvotes: 0

Infinity James
Infinity James

Reputation: 4735

I can only imagine viewWillAppear: is not being called on each subsequent tap of the UITabBarItem.

Have you set a breakpoint in the method to check?

If it is in fact thew viewWillAppear: method not being called, I would suggest placing this code somewhere which is called on each tap on the UITabBarItem.

Upvotes: 1

Related Questions