解决Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!问题

统一弹登录页面,有的是在push出来的页面弹登录页面,有的是在present页面弹登录页面
说明 :
例如:A present B A就是presenting view controller(弹出VC); B就是presented view controller(被弹出VC);

解决方案:

//登录
- (void)presentLoginVC
{
    PhoneLoginViewController *loginVC = Storyboard(@"Main", @"PhoneLoginViewController");
    UINavigationController *loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
    UIViewController *viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    /* viewController.presentedViewController只有present才有值,push的时候为nil
     */

//防止重复弹
    if ([viewController.presentedViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navigation = (id)viewController.presentedViewController;
        if ([navigation.topViewController isKindOfClass:[PhoneLoginViewController class]]) {
            return;
        }
    }
    if (viewController.presentedViewController) {
        //要先dismiss结束后才能重新present否则会出现Warning: Attempt to present <UINavigationController: 0x7fdd22262800> on <UITabBarController: 0x7fdd21c33a60> whose view is not in the window hierarchy!就会present不出来登录页面
        [viewController.presentedViewController dismissViewControllerAnimated:false completion:^{
            [viewController presentViewController:loginNav animated:true completion:nil];
        }];
    }else {
        [viewController presentViewController:loginNav animated:true completion:nil];
    }
}

2.Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
这个是自定义cell调用了基类的设置高度的方法,在tableview没有实现- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath这个代理方法,然后就会出现这个警告。

推荐阅读更多精彩内容