今天在項目中碰到了一個小問題,點擊側邊欄的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];
});
...
}
引申傳送門,查了度娘才看到這個答案。