2017-07-28 55 views
0

我正在构建一个应用程序,在该应用程序中,如果您第一次打开该应用程序,并且在任何其他时间打开该应用程序,则该应用程序会将该应用程序引导至配置文件注册表视图。我怎样才能以编程方式实现这一点,我所见过的所有东西只将按钮连接到一个视图。如何根据swift中的按钮单击条件执行不同的segue?

@IBAction func NextViewController(_ sender: UIButton) { 
    if launchedBefore { 
     print("Not first launch.") 

    } else { 
     print("First launch, setting UserDefault.") 


     UserDefaults.standard.set(true, forKey: "launchedBefore") 
    } 
} 
+2

为什么你不喜欢你的解决方案? –

回答

1

我想,你正试图连接按钮执行segue与多个ViewController吗?这是不可能的

相反,你必须视图控制器

之间增加两个viewControllers之间的赛格瑞连接赛格瑞:

从Interface Builder中,按Ctrl +拖动要两个viewControllers之间链接。您应该看到:

enter image description here

现在根据你调理你应该使用标识符像下面执行赛格瑞:

@IBAction func NextViewController(_ sender: UIButton) { 
      if launchedBefore { 
     /*Use the Identifier you given in story Board*/ 
       self.performSegue(withIdentifier: "otherVC", sender: self) 

      } else { 
    /*Use the Identifier you given in story Board*/ 
     self.performSegue(withIdentifier: "register", sender: self)) 
       UserDefaults.standard.set(true, forKey: "launchedBefore") 
      } 
     } 

约赛格瑞详细描述这个问题,一看便知How to connect two view controllers to one button in storyboard?

+0

男人,你值得一枚勋章:)非常感谢你的帮助! –

+0

人们请UPVOTE JAYDEEP! –

相关问题