项目结构分析
底部导航UITabBarController+导航栏UINavigationController结构的iOS项目分析
1、退出登录切换rootViewController时、必须要dismiss掉present出来的控制器、要不然控制器不会释放、造成内存泄漏,push出来的就不需要处理、切换就会释放
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController *root = keyWindow.rootViewController;
if ([root presentedViewController]) {
[rootdismissViewControllerAnimated:NO completion:nil];
}
keyWindow.rootViewController = LoginviewController
2、需要切换底部导航的时候、也必须要dismiss掉present出来的控制器、要不然页面没有反应、不会切换
1、重复第一步代码
2、UITabBarController *rootVC = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
if(rootVC && [rootVC isKindOfClass:[UITabBarController class]]) {
if(rootVC.viewControllers.count>1) {
rootVC.selectedIndex=1;
UINavigationController *navigationController = (UINavigationController *)rootVC.selectedViewController;
if([navigationController isKindOfClass:[UINavigationController class]]) {
// 先回到根
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:MessageVC animated:YES];
网友评论