Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UISwitch更改初始ViewController_Ios_Swift_Xcode7_Uiswitch - Fatal编程技术网

Ios 使用UISwitch更改初始ViewController

Ios 使用UISwitch更改初始ViewController,ios,swift,xcode7,uiswitch,Ios,Swift,Xcode7,Uiswitch,我想在我的应用程序中添加一个选项来更改初始ViewController,以便用户可以跳过登录视图 class SettingsViewController: UIViewController { var vc: UIViewController? @IBOutlet var changeInitialView: UISwitch? @IBAction func changeButton(sender: UIButton) { if changeInitialView!.on {

我想在我的应用程序中添加一个选项来更改初始ViewController,以便用户可以跳过登录视图

class SettingsViewController: UIViewController {

var vc: UIViewController?

@IBOutlet var changeInitialView: UISwitch?

@IBAction func changeButton(sender: UIButton) {
    if changeInitialView!.on {
        print("Switch is off")
        vc = UIStoryboard(name: "MenuViewController", bundle: nil).instantiateViewControllerWithIdentifier("MenuViewController")
        changeInitialView!.setOn(false, animated:true)
    } else {
        print("Switch is on")
        changeInitialView!.setOn(true, animated:true)
    }
}
如果我这样尝试,它总是向我显示以下失败消息:
在捆绑包中找不到名为“MenuViewController”的情节提要…

第一个VC是
UIViewController
对象,第二个我认为
MenuViewController
是您的
viewcontroller
名称,而不是情节提要名称。 请尝试以下步骤:

  • 最初,你必须有一个初始VC,从那里你的应用程序流将开始
  • 现在,如果您想在下次启动应用程序时更改初始VC,只需创建一个标志并将其值存储在
    NSUserDefaults
  • didfishlaunchingwithoptions
    中,选中
    NSUserDefaults
    中的标志,并相应地设置初始VC
    步骤3的代码显示在我之前共享的链接中。

    第一个VC是
    UIViewController
    对象,第二个我认为
    MenuViewController
    是您的
    viewcontroller
    名称,而不是故事板名称。 请尝试以下步骤:

  • 最初,你必须有一个初始VC,从那里你的应用程序流将开始
  • 现在,如果您想在下次启动应用程序时更改初始VC,只需创建一个标志并将其值存储在
    NSUserDefaults
  • didfishlaunchingwithoptions
    中,选中
    NSUserDefaults
    中的标志,并相应地设置初始VC
    步骤3的代码显示在我之前共享的链接中。

    是的,我也尝试过在故事板(“菜单”)中使用该名称,但效果不太好。你说vc是UIViewController对象是什么意思?我必须更改吗?故事板名称是什么?故事板名称是“菜单”,看看这是否可以帮助您。Thx但现在我遇到一个错误,因为它找不到第一个初始ViewController的名称。这与现在的错误相同,但在启动应用程序时显示allready。不知怎的,我写的名字不对,但我试过标题和田园诗,我也试过在故事板(“菜单”)中用名字,但效果不太好。你说vc是UIViewController对象是什么意思?我必须更改吗?故事板名称是什么?故事板名称是“菜单”,看看这是否可以帮助您。Thx但现在我遇到一个错误,因为它找不到第一个初始ViewController的名称。这与现在的错误相同,但在启动应用程序时显示allready。不知怎的,我写的名字不对,但我试过了标题和ID