简体   繁体   中英

Root View controller is deallocated so how do I retain it or add it to my navigation controller again

After I logout using this:

- (IBAction) logoutButtonPressed:(UIButton *)sender
{
    [Users logOut];

    [self.navigationController popToRootViewControllerAnimated:YES];
}

The screen goes black if I have been logged in for like 12 hours. I guess the rootview controller is deallocated.

This is how it's created in appDelegate.m:

- (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];
}

How can I make startviewcontroller show again? Or whatever the root is?

When you assign self.window.rootViewController, a strong reference is created for that object and hence with ARC it would not be deallocated unless the object pointing to it was deallocated. So your StartViewController is the rootViewController of a navigation controller. How do you add the controller where you call the poptoRootViewController? When performing the pop, get the view controllers array of the navigation controller and make sure that your root view controller is intact.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM