**Changing the window.rootViewController to the tabbarcontroller
when the user signs in and if not set the window.rootview controller
as the login view controller.**
是做這件事的最佳方式, 最初如果用戶不是比LoginViewController登錄將是RootViewController的其他tabBarController將RootViewController的,並隨着用戶註銷改變RootViewController的到LoginViewController。
更新:試試這個,這將起作用。如果不清楚明白告訴我,我會給你一個工作項目。
Bydefault InitialViewController從您的主要故事板是 實例化,當你的應用程序啓動時自動顯示。若要 防止這種情況發生,您需要從您的info.plist文件中刪除UIMainStoryboardFile 設置。
沒有默認視圖控制器,您現在可以在應用程序啓動時以編程方式自由創建一個 。
在這裏我寫了一個小例子,在這行下面。創建兩個沒有xib的視圖控制器FirstViewController和SecondViewController並添加比MainStoryboard_iPhone和Appdelegate.m中的實現這些方法。
- (BOOL)應用:(UIApplication的*)應用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/*
call any of the two methods below, it will change the RootViewController accordingly
*/
// [self firstRootViewController]; // make FirstViewController Root view controller
[self secondRootViewController]; // make SecondViewController Root view controller
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (無效)firstRootViewController {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
FirstViewController *first = [sb instantiateViewControllerWithIdentifier:@"FirstViewController"];
[self.window setRootViewController:first];
}
- (無效)secondRootViewController {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
SecondViewController *second = [sb instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.window setRootViewController:second];
}
現在設置的viewController在MainStoryboard_iPhone.storyboard
跟第4個一起 –