iOS根视图切换之后,上一个根视图如何销毁

一般APP首次启动,会有登录界面,需要在AppDelegate里设置rootViewController

self.window.rootViewController  = loginVC;

//登录成功后,切换根视图,上一个根视图自动释放
UITabBarController *tabbar = [[UITabBarController alloc] init];
[UIApplication sharedApplication].keyWindow.rootViewController = tabbar;

如果,根视图为A,A --> loginVC是经过 present 模态跳转过来的

self.window.rootViewController  = A;
......
//模态跳转
[A presentViewController:nav animated:YES completion:nil];

//登录成功后,切换根视图,需要dismiss释放上一个根视图
[self dismissViewControllerAnimated:NO completion:^{
        UITabBarController *tabbar = [[UITabBarController alloc] init];
        [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
}];

你可能感兴趣的:(iOS根视图切换之后,上一个根视图如何销毁)