編譯器給出的提示如下:
Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!
解決辦法:
ReleaseDiscussVC *releaseVC = [ReleaseDiscussVC new];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:releaseVC];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
/* rootVC.presentedViewController只有present才有值,push的時候為nil
*/
//防止重復(fù)彈
if ([rootVC.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigation = (id)rootVC.presentedViewController;
if ([navigation.topViewController isKindOfClass:[ReleaseDiscussVC class]]) {
return;
}
}
if (rootVC.presentedViewController) {
//要先dismiss結(jié)束后才能重新present否則會出現(xiàn)
//Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!
//就會present不出來登錄頁面
[rootVC.presentedViewController dismissViewControllerAnimated:false completion:^{
[rootVC presentViewController:nav animated:true completion:nil];
}];
}else {
[rootVC presentViewController:nav animated:true completion:nil];
}