我希望第一次加载我的应用程序时,它能够从我设置的首选项视图开始,而每次以后则从主视图开始。
我找不到一种方法来检测是否是第一次运行应用程序。有什么建议吗?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
NSUserDefaults *padFactoids;
int launchCount;
padFactoids = [NSUserDefaults standardUserDefaults];
launchCount = [padFactoids integerForKey:@"launchCount" ] + 1;
[padFactoids synchronize];
NSLog(@"this is the number: %i of times this app has been launched", launchCount);
if ( launchCount == 1 )
{
NSLog(@"this is the FIRST LAUNCH of the app");
// do stuff here as you wish
bbb = [[Blue alloc]init];
[window addSubview:bbb.view];
}
if ( launchCount >= 2 )
{
NSLog(@"this is the SECOND launch of the damn app");
// do stuff here as you wish
rrr = [[Red alloc]init];
[window addSubview:rrr.view];
}
[window makeKeyAndVisible];
return YES;
}
这里红色和蓝色是uiviewcontroller的子类,两个类中唯一的区别是在-(void)viewDidLoad{ self.view.backgroundcolor = [UIColor redColor]; }中,红色类显示红色背景颜色,而蓝色类显示蓝色背景颜色。但是当我执行应用程序时,它只显示蓝色,不显示红色。我错在哪里?第二次运行应用程序时,我该怎么做才能显示红色......