我有一个与用户“Flocked”类似的问题(请参阅此处的问题:Load an other View from applicationDidFinishLaunching in the AppDelegate),但是在阅读了他的帖子后我没有设法解决,也许我的情况与他的不同。
我有didFinishLaunchingWithOptions
一个例程来检查应用程序是否是第一次运行(也来自另一个用户):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
}
else{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
NSLog(@"First run");
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
如果 firstLaunch 发生,我无法加载另一个视图InfoView
(用于设置的视图)。我试过了:
InfoView *infoView = [[InfoView alloc]init];
[self presentViewController:infoView animated:YES completion:nil];
里面if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
但没有运气。有什么想法或帮助吗?