【发布时间】:2014-03-03 21:03:05
【问题描述】:
您好,我目前正在开发一个应用程序,当您打开应用程序时,会使用带有 PageViewController 的 UIViewController 作为简短教程。我想知道你是否可以使用 UISWitch 来“隐藏”那个 UIViewController 以便下次启动应用程序时它直接进入“主视图”?
谢谢 PS。英语是我的第二语言。
【问题讨论】:
您好,我目前正在开发一个应用程序,当您打开应用程序时,会使用带有 PageViewController 的 UIViewController 作为简短教程。我想知道你是否可以使用 UISWitch 来“隐藏”那个 UIViewController 以便下次启动应用程序时它直接进入“主视图”?
谢谢 PS。英语是我的第二语言。
【问题讨论】:
如果你只是想第一次显示它,你不需要 UISwitch。只需使用NSUserDefaults 来记住您之前是否运行过。
在您的application:didFinishLaunchingWithOptions: 方法中:
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"RunBefore"]) {
//show pagecontroller here
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"RunBefore"]
}
【讨论】:
首先你需要为你的开关设置一个动作:
- (IBAction)valueChanged:(UISwitch *)theSwitch
{
[[NSUserDefaults standardUserDefaults] setBool:theSwitch.isOn
forKey:@"DontShowViewContoller"];
}
然后,下一次,当您想要显示您检查的视图控制器时:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"DontShowViewContoller"] == NO)
{
[self showYourViewController]
}
【讨论】: