【发布时间】:2014-03-05 20:03:35
【问题描述】:
我在我的应用程序中实现了UINavigationController,我想要实现的是以编程方式确定该应用程序是否已启动。我需要这个来确定应该向用户显示哪个视图。如果这是第一次运行,我需要显示与其他任何时候不同的视图。
当我不使用 UINavigationController 时很容易,但在这种情况下,当我使用我的方法时,我将摆脱 UINavigationController 层次结构。
这是我用来确定首次运行的方法:
+ (void)executeBlockAtTheFirstRun:(void (^)())firstRunBlock atAnotherRun:(void (^)())anotherRunBlock
{
// Checking whether HasAlreadyBeenLaunched key is set to be YES
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasAlreadyBeenLaunched"]) {
// Running block given by the user when this isn't the first run of the app
anotherRunBlock();
// Uncomment this if you want the log
//NSLog(@"Application has already been launched");
} else {
// Seeting the bool value for key HasAlreadyBeenLaunched and synchronising user defaults
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasAlreadyBeenLaunched"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Running the block with code provided by the user for the first run of the app
firstRunBlock();
// Uncommeent this f you want the log
// NSLog(@"This is the first run");
}
}
所以当我放入完成块时:
NSString *storyboardID = [self hasEverBeenLaunched]? @"MainView" : @"LoginView";
self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:storyboardID];
并将所有内容放入 AppDelegate.m 我可以管理视图,但正如我所说,我的 UINavigationController 层次结构消失了。我应该怎么做才能让一切正常运行?
【问题讨论】:
标签: ios iphone objective-c uiviewcontroller uinavigationcontroller