我的UINavigationController
在我的应用程序中实现,我试图实现的是以编程方式确定应用程序是否已启动。我需要这个来确定我应该向用户展示哪个视图。如果这是第一次运行,那么我需要在任何其他时间显示不同的视图。在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
层次结束了。我应该怎么做才能使所有工作都像它应该那样?
谢谢这是我一直在寻找的部分,但有了这个解决方案,所有层次结构都丢失了......我希望找到像调用'rootViewController'这样的东西,并在其中确定第一次运行,并在必要时推送到另一个视图去拥有这个后退按钮。 – cojoj