iOS 關於側邊欄模態出VC出現的問題

zhf_Zachariah發表於2017-12-13

今天在專案中碰到了一個小問題,點選側邊欄的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];
    });
   ...
}
複製程式碼

引申傳送門,查了度娘才看到這個答案。

相關文章