【问题标题】:Use UISwitch to Hide UIViewContoller?使用 UISwitch 隐藏 UIViewContoller?
【发布时间】:2014-03-03 21:03:05
【问题描述】:

您好,我目前正在开发一个应用程序,当您打开应用程序时,会使用带有 PageViewController 的 UIViewController 作为简短教程。我想知道你是否可以使用 UISWitch 来“隐藏”那个 UIViewController 以便下次启动应用程序时它直接进入“主视图”?

谢谢 PS。英语是我的第二语言。

【问题讨论】:

    标签: ios ios7 uiswitch


    【解决方案1】:

    如果你只是想第一次显示它,你不需要 UISwitch。只需使用NSUserDefaults 来记住您之前是否运行过。

    在您的application:didFinishLaunchingWithOptions: 方法中:

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"RunBefore"]) {
        //show pagecontroller here
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"RunBefore"]
    
    }
    

    【讨论】:

      【解决方案2】:

      首先你需要为你的开关设置一个动作:

      - (IBAction)valueChanged:(UISwitch *)theSwitch
      {
          [[NSUserDefaults standardUserDefaults] setBool:theSwitch.isOn
                                                  forKey:@"DontShowViewContoller"];
      }
      

      然后,下一次,当您想要显示您检查的视图控制器时:

      if([[NSUserDefaults standardUserDefaults] boolForKey:@"DontShowViewContoller"] == NO)
      {
          [self showYourViewController]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多