2017-04-25 5 views
1

AppDelegateは、ユーザーがログインしているかどうかをチェックし、ユーザーがログインしていない場合は、ユーザーがアプリケーション内のどこからでもformSheet viewを表示します。AppDelegateからフォームシートを表示するには?

どうすればよいですか?

答えて

0

あなたはappdelegateクラスにrootViewControllerようなウィンドウプロパティを使用することができます

これを試してください: -

if let rootVC = self.window?.rootViewController as? YourViewController { 
     //Add the code here to present signupviewcontroller as form sheet 
} 

あなたrootVCこれは想定していUINavigationController

if let nsvigationVC = self.window?.rootViewController as? UINavigationController { 
     if yourVC = nsvigationVC.visibleViewController { 
      //Add the code here to present signupviewcontroller as form sheet 
      let sb = UIStoryboard(name: “Main”, bundle: nil) //get signupviewcontroller from storyboard 
      let signupVC = sb.instantiateViewControllerWithIdentifier("signupviewcontroller") as! signupviewcontroller 
      signupVC.modalPresentationStyle = UIModalPresentationStyle.FormSheet 
      signupVC.preferredContentSize = CGSize(width: 365, height: 500) // set content size as per your requirement 
      yourVC.presentViewController(signupVC, animated: true, completion: nil) 
     } 

    } 
+0

visibleViewControllerプロパティを使用するよりも、UINavigationControllerある場合ルートコントローラは最上位のビューコントローラです。この質問に基づいて、これは常にそうであるとは限りません。 – rmaddy

+0

@ rmaddy Answer updated、 –

+0

フォームシートとして 'signupviewcontroller'を提示するコードは何でしょうか? – Berry

関連する問題