编译器给出的提示如下:
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
*/
//防止重复弹
if ([rootVC.presentedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigation = (id)rootVC.presentedViewController;
if ([navigation.topViewController isKindOfClass:[ReleaseDiscussVC class]]) {
return;
}
}
if (rootVC.presentedViewController) {
//要先dismiss结束后才能重新present否则会出现
//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];
}