2012-03-13 6 views
4

ここに状況があります。私はAppdelegate.mにNSTimerを持っています。これはユーザーの場所を確認し、彼が地域外にいる場合にログアウトする方法を実行します。それが起こると、私はログインビューコントローラをロードします。しかし、次のコード行ではVCを見ることができますが、テキストフィールドをクリックして入力するとsigbartが得られます。任意のアイデアをどのようにアプリケーションのデリゲートからの最初のVCを読み込むには?アプリケーションデリゲートからログインビューコントローラをロードする方法

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
      LoginViewController *loginViewController = (LoginViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Login"]; 
      [self.window addSubview:loginViewController.view]; 
      [self.window makeKeyAndVisible]; 
+0

あなたはこれらの答えの一つが正しいことが判明した場合、あなたは正しい –

答えて

1

これは私がビューを変更したいときに私が使用するコードです:そのコードを使用して

#import "LoginViewController.h" 

LoginViewController *screen = [[LoginViewController alloc] initWithNibName:nil bundle:nil]; 
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[self presentModalViewController:screen animated:YES]; 

//or 

[self.window addSubView:screen]; 

は、そのブランドの新しいインスタンスを作成し、それを表示するので、それはあなたの質問を達成する必要があります。あなたはいくつかのものを動かしなければならないかもしれませんが、うまくいくはずです。

これ以上ヘルプが必要な場合はお知らせください。

希望すると、これが役立ちます。

+0

デビッドとしてそれをマークする気だろう、それは動作しません。あなたが言ったようにログインVCを初期化すれば何も起こりません。 – audiophilic

+0

エラーメッセージがあります – David

11

私はこれをかなり苦労しています。ここでは、あなたはまだエラーがある場合、それはあなたのLoginViewController、ないAppDelegate遷移に関係している私

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
LoginViewController *loginViewController = (LoginViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"Login"]; 

//set the root controller to it 
self.window.rootViewController = loginViewController 

のために働いていたものです。お役に立てれば。

+0

VCをself.window.rootViewControllerに割り当てることはできません。 – Dean

4

オーディオとフラビの両方のアプローチは問題ありません。しかし、両方のコード行が1行追加されていません。

まず、UIWindowオブジェクトを割り当てて初期化する必要があることがわかりました。私はなぜ、オブジェクトを初期化するのが問題を解決したのかわかりません。

self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

audiophilicのアプローチ:

self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 

ResultsInListViewController *resultsInListViewController = (ResultsInListViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"ResultsInListViewController"]; 

[self.window addSubview:resultsInListViewController.view]; 

[self.window makeKeyAndVisible]; 

Flaviuのアプローチ:

self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 

ResultsInListViewController *resultsInListViewController = (ResultsInListViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"ResultsInListViewController"]; 

[self.window setRootViewController:resultsInListViewController]; 

[self.window makeKeyAndVisible]; 
関連する問題