我正在學習iOS並開發我的第一個iPone應用程序。我想爲我的應用添加一項功能:如果用戶之前登錄過,我想將用戶重定向到主視圖。否則,我想將用戶重定向到登錄視圖。如何決定AppDelegate中的rootView
我已閱讀ios change storyboard default view controller at run time,但我想知道我是否可以編寫決定AppDelegate中根視圖的代碼。因此,我不會有一個永遠不會推出的觀點。
這是我的AppDelegate代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
MainViewController *rootVC = [[MainViewController alloc] init];
if (userNeverLogin) {
LoginViewController *rootVC = [[LoginViewController alloc] init];
}
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC];
return YES;
}
這個代碼不工作(它不會觸發任何錯誤,但它會顯示沒有在模擬器)。我應該如何修改它?或者在AppDelegate中做這個功能是不可能的?
對不起,我是iOS的新手。我希望這個問題不愚蠢。
有可能你實際使用故事板要做到這一點在AppDelegate中 – ekims
@布賴恩? –
是的,我正在使用故事板。 – Brian