Reputation: 25701
I created a RootViewController in my app delegate like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
StartViewController *viewController = [[StartViewController alloc] init];
StartNavigationController *navigationController=[[StartNavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
}
When I hit the logout button, I want to send the user back to the rootview controller:
- (IBAction) logoutButtonPressed:(UIButton *)sender
{
[Users logOut];
[self.navigationController popToRootViewControllerAnimated:YES];
}
This works fine when I run it on my iPhone 4s (testing iphone 6 when it arrives), but if I leave the user logged in for more than a day and click the logout button, the screen slides to black.
Why is my root view controller not calling my startviewcontroller after like 24 hours or so?
Upvotes: 0
Views: 687
Reputation: 12719
I am trying to put an answer, I guess it should work for you. First you check for StartViewController
whether it exist in navigationController stack or, not. As per your stack StartViewController
should be your first controller added in navigationController
.
StartViewController *loginController=[self.navigationController.viewControllers objectAtIndex:0];
if(loginController){
[self.navigationController popToViewController:loginController animated:YES];
}else{
NSMutableArray *controllers=[[NSMutableArray alloc] init];
loginController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
[controllers addObject:loginController];
[controllers addObjectsFromArray:self.navigationController.viewControllers];
self.navigationController.viewControllers=[[NSArray alloc] initWithArray:controllers];
[self.navigationController popToRootViewControllerAnimated:YES];
}
I think it should work.
Cheers.
Upvotes: 1