您可以通過兩種方式更改初始控制器:
- 檢查「是初始VC」複選框在界面生成器或在-application
- 配置它:didFinishLaunchingWithOptions:方法中
更改初始查看U控制器唱申請委託
在 - 應用中:didFinishLaunchingWithOptions:在您的應用程序委託(AppDelegate.m)添加if/else語句來檢查教程的必要性:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if (![[NSUserDefaults standardUserDefaults] boolForKey: @"FirstLaunch"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
[[NSUserDefaults standardUserDefaults] synchronize];
/*** load vc ***/
}
return YES;
}
要設置你必須初始化初始控制器窗口屬性,創建VC並將其設置爲根:
// 1. Initialize window
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
// 2. Get storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 3. Create vc
TutorialViewController *tutorialViewController = [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([TutorialViewController class])];
// 4. Set as root
self.window.rootViewController = tutorialViewController;
// 5. Call to show views
[self.window makeKeyAndVisible];
希望它能幫助!
我收到錯誤消息「屬性'故事板'找不到'App Delegate'類型的對象」任何想法?非常感謝你的幫助! – user3808557 2014-11-05 19:39:08
感謝您的評論!編輯我的答案。您可以在主目標信息屏幕上找到故事板名稱。通常它被稱爲'Main'或'Main_iphone' – 2014-11-06 17:04:31
謝謝!但現在我收到一條錯誤消息,說「使用未聲明的標識符」導航器VC'「我該如何解決這個問題?非常感謝您的幫助 – user3808557 2014-11-25 00:39:46