我正在尝试创建一个我觉得在使用之前需要指导的应用程序但是我在重新启动应用程序时遇到问题并且它回到了入门视图而不是主视图(UIViewController)我有一个plist设置,如果用户点击Start App,它会保存一个bool,它保存一个YES bool,但是当你第一次启动它时,它默认设置为A NO Bool。继承了appDelegate的代码
从
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"GetStartedCheck.plist"];
NSMutableDictionary *myDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
BOOL myBool = [[myDict objectForKey:@"alreadyUsedApp"] boolValue];
[myDict writeToFile:filePath atomically:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (myBool == NO)
{
self.startedViewController = [[GetStartedViewController alloc] initWithNibName:@"GetStartedViewController_iPhone" bundle:nil];
}
else if (myBool == YES)
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
}
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
if (myBool == NO)
{
self.window.rootViewController = self.startedViewController;
}
else if (myBool == YES)
{
self.window.rootViewController = self.viewController;
}
[self.window makeKeyAndVisible];
return YES;
是否有任何我可以阅读和关注的教程或任何可以给我建议的人。
答案 0 :(得分:0)
你可以使用NSUserDefaults,这很容易
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL myBool = YES;
id exist = [[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"];
if(exist==nil){
myBool = NO;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"FirstRun"];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (myBool == NO)
{
self.startedViewController = [[GetStartedViewController alloc] initWithNibName:@"GetStartedViewController_iPhone" bundle:nil];
}
else if (myBool == YES)
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
}
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
if (myBool == NO)
{
self.window.rootViewController = self.startedViewController;
}
else if (myBool == YES)
{
self.window.rootViewController = self.viewController;
}
[self.window makeKeyAndVisible];
return YES;
}