【发布时间】:2013-12-16 20:17:38
【问题描述】:
我目前正在编写一个应用程序,该应用程序需要在第一次运行时加载一个不同的视图,用户可以在其中选择其首选设置。这是代码
实现AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Determining Storyboard identifier for first view
// Determining Storyboard identifier for first view
NSString *storyboardID = [self hasEverBeenLaunched]? @"MainView" : @"LoginView";
// Setting proper view as a rootViewController
self.window.rootViewController = [self.window.rootViewController.storyboardinstantiateViewControllerWithIdentifier: @"view45"] ;
然后继续下面的代码:
- (BOOL)hasEverBeenLaunched
{
// A boolean which determines if app has eer been launched
BOOL hasBeenLaunched;
// Testig if application has launched before and if it has to show the home-login screen to login
// to social networks (facebook, Twitter)
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasAlreadyLaunched"]) {
// Setting variable to YES because app has been launched before
hasBeenLaunched = YES;
NSLog(@"App has been already launched");
} else {
// Setting variable to NO because app hasn't been launched before
hasBeenLaunched = NO;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasAlreadyLaunched"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"This is the first run ever...");
}
return hasBeenLaunched;
}
只是一些简短的说明:视图 45 是初始启动视图,它应该只显示一次,否则主视图控制器在属性下被勾选为初始视图控制器(总是在开始时加载的那个,之后第一次运行)
所以问题是它只加载视图 45,即第一个运行视图,但究竟是什么原因造成的呢?
【问题讨论】:
-
12 分钟后提出问题?真的吗?!?
标签: ios objective-c view