2017-11-25 11 views
0

私のタブバーコントローラの2番目の項目では、私はモーダルで提示したいナビゲーションコントローラを持っています。アプリケーションがアクティブなコントローラをモーダルに表示しようとしました - ナビゲーションコントローラ

未知の例外 'NSInvalidArgumentException'が原因でアプリケーションを終了しています。理由: 'アプリケーションがアクティブなコントローラをモーダルに表示しようとしました。'

次に、アプリケーションがクラッシュし、アプリケーションデリゲートに移動します。

これは、これまで

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { 
    if let restoreID = viewController.restorationIdentifier { 
     if restoreID == "NavigationCamera" { 
      if let nav = tabBarController.viewControllers![tabBarController.selectedIndex] as? UINavigationController { 
       print("Nav is allowed") 
       //let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView") 

       tabBarController.present(nav, animated: true, completion: { 
        print("complete") 
       }) 
       return false 
      } 
     } 
    } 
    return true 
} 

This is how my navigation controller is connected to my Tab Bar Controller

答えて

0

私が持っているコードであるあなたは、アプリがクラッシュした理由です、UITabBarControllerですでにアクティブになっているのViewControllerを提示しようとしています。 これを試してみてください

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { 
    if let restoreID = viewController.restorationIdentifier { 
     if restoreID == "NavigationCamera" { 
       print("Nav is allowed") 
       let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView") as! UIViewController 
       tabBarController.present(UINavigationController.init(rootViewController: newVC), animated: true, completion: { 
        print("complete") 
       }) 
       return false 
     } 
    } 
    return true 
} 
関連する問題