8

私はiOSプログラミングの新機能があり、タブバーコントローラー(FirstViewController、SecondViewControllerなど)が接続されたタブバーコントローラーを搭載したiPadアプリを開発しています。現在、Tab Bar Controllerはアプリのデフォルトの開始点に設定されています。私はそのポイントに達する前にユーザーを認証できるようにしたいので、ストーリーボードに単独で浮かぶLoginViewControllerという別のView Controllerを追加しました。ストーリーボードでpresentModalViewControllerを使用する

私がしたいことは、アプリケーションが読み込みを許可し、didFinishLaunchingで、認証が完了するまでログインページを表示してから拒否することです。私は過去のカップルの日の周りを検索してきましたが、私が試みてきたことはすべて失敗しました。

私の最新の試みは、任意の助けをいただければ幸いです

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 

UINavigationController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"]; 

loginVC.modalPresentationStyle = UIModalPresentationFullScreen; 

[self.window.rootViewController presentModalViewController:loginVC animated:YES]; 

ました。それはコンパイルされ、実行されますが、ビューはまったく表示されず、なぜこれが起こっているのか本当に混乱しています。

答えて

12

問題は、私は実際にはそれだけのUIViewControllerたUINavigationController、としてそれをインスタンス化しようとしていたでした。 appDelegate.mのapplicationDidBecomeActiveでこれを呼び出すと、このトリックが実行されました。スウィフト2では

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
UIViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"loginVC"]; 
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;  
[self.window.rootViewController presentModalViewController:loginVC animated:YES]; 
2

表示されるビューではなく、現在表示されているviewControllerから "presentModalViewController"を呼び出す必要があります。おそらく、このような何か:

[self.window.rootViewController presentModalViewController:loginVC animated:YES]; 
2

、これは以下のようになります。

if let loginController: LoginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("StoryboardControllerID") as? LoginViewController { 
    loginController.modalPresentationStyle = .FullScreen 
    self.window?.rootViewController?.presentViewController(loginController, animated: true, completion: {() -> Void in 
     // do stuff! 
    }) 
} 
関連する問題