我想首次打开应用时才显示屏幕教程。 但问题是当我第一次导航到我的应用程序并返回rootviewcontroller所有时间显示教程屏幕。我想显示“菜单”屏幕。
如何在教程屏幕后将RootViewController设置为我的MenuViewController?
谢谢!
我在appdelegate.m中有这段代码:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"ISFIRSTTIME"] isEqualToString:@"NO"]) {
controller = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
}
else {
controller = [[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil];
}
_navController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window setRootViewController:_navController];
[self.window makeKeyAndVisible];
答案 0 :(得分:1)
设置为else条件,
[[NSUserDefaults standardUserDefaults]setValue:@"NO" forKey:@"ISFIRSTTIME"];
[[NSUserDefaults standardUserDefaults] synchronize];
答案 1 :(得分:0)
我在这个项目中这样做,
NSString *identifier;
BOOL isSaved = [[NSUserDefaults standardUserDefaults] boolForKey:@"loginSaved"];
if (isSaved)
{
identifier=@"home1";
}
else
{
identifier=@"dis1";
}
UIStoryboard * storyboardobj=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *screen = [storyboardobj instantiateViewControllerWithIdentifier:identifier];
[self.window setRootViewController:screen];
希望这会有所帮助:)
答案 2 :(得分:0)
做类似的事情,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"ISFIRSTTIME"] isEqualToString:@"NO"]) {
controller = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
}
else {
controller = [[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil];
}
_navController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window setRootViewController:_navController];
[self.window makeKeyAndVisible];
//Setting "ISFIRSTTIME" to "NO" : it will be "NO" after first time you open the app
[[NSUserDefaults standardUserDefaults]setValue:@"NO" forKey:@"ISFIRSTTIME"];
[[NSUserDefaults standardUserDefaults] synchronize];
答案 3 :(得分:0)
将它与对象进行比较而不是方法。 就像拿bool isfirsttime =你的NSuserdefault方法一样。 使用 if(isfirsttime)
{} 其他 {}