2017-07-28 28 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! –

相關問題