2017-05-27 7 views
0
let appDelegate = UIKit.UIApplication.shared.delegate! 

     if let tabBarController = appDelegate.window??.rootViewController as? UITabBarController { 
      let storyboard = UIStoryboard.init(name: "Main", bundle: nil) 
      let signInVC = storyboard.instantiateViewController(withIdentifier: "SignInVC") as! SignInVC 

      guard !signInVC.isBeingPresented else { 
       log.warning("Attempt to present sign in sheet when it is already showing") 
       return 
      } 

      signInVC.modalPresentationStyle = UIModalPresentationStyle.formSheet 

      tabBarController.present(signInVC, animated: true, completion: nil) 
     } 

signInVCが表示されていますが、このコードは複数回呼び出すことができます。私はすでに、このチェックを追加しました:「提示中に提示しようとしていますが、まだチェックの後に表示されていますか?

guard !signInVC.isBeingPresented else { 
    log.warning("Attempt to present sign in sheet when it is already showing") 
    return 
} 

を、このエラーを回避していないよう:

Warning: Attempt to present <App.SignInVC: 0x101f2f280> on <UITabBarController: 0x101e05880> which is already presenting <App.SignInVC: 0x101f4e4c0> 

答えて

1

あなたguardは有効なチェックではありません。 isBeingPresentedは、まだ提示されていない新しいView Controllerインスタンスで呼び出されています。したがって、isBeingPresentedは常にfalseになります。それに加えて、そのプロパティは、ビューコントローラのview[Will|Did]Appearメソッド内からのみ使用できます。

tabBarControllerがすでに別のView Controllerを提示しているかどうかを確認してください。

最後に、サインインビューコントローラーを作成し、表示する必要がある場合にのみセットアップします。

let appDelegate = UIKit.UIApplication.shared.delegate! 

if let tabBarController = appDelegate.window?.rootViewController as? UITabBarController { 
    if tabBarController.presentedViewController == nil { 
     let storyboard = UIStoryboard.init(name: "Main", bundle: nil) 
     let signInVC = storyboard.instantiateViewController(withIdentifier: "SignInVC") as! SignInVC 
     signInVC.modalPresentationStyle = UIModalPresentationStyle.formSheet 

     tabBarController.present(signInVC, animated: true, completion: nil) 
    } 
} 
+0

これで問題が解決したのですか、それでも問題が解決しましたか? – rmaddy

関連する問題