iOS 关于侧边栏模态出VC出现的问题

170 阅读1分钟

今天在项目中碰到了一个小问题,点击侧边栏的Button模态出一个VC,而这个VC恰好是根视图的VC。运行的时候报了一个错误,记录下来。。。

刚开始我是直接用self调用的presentViewController,出现了报错,但是程序正常运行。。。

侧边栏模态问题.png

解决方法:

/**退出登录*/
-(void)clickExitButton:(UIButton *)sender{
   ...
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //跳转到登录界面
        LoginViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
         AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [delegate.window.rootViewController presentViewController:[[MyNavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
    });
   ...
}

引申传送门,查了度娘才看到这个答案。