您可以從登錄屏幕連接兩個塞格斯。
在故事板,連接從登錄屏幕到OTP屏幕SEGUE,並從登錄屏幕主屏幕另一SEGUE。請記住從故事板中的控制器開始拖動,而不是控制器中的任何視圖。
給每個原因請看在右側面板的標識符。我將調用第一個segue(登錄 - > OTP)「showOTP」和第二個segue(登錄 - >主屏幕)「showHome」。
if語句:
func LoginDone() {
if (registeredUser()){
performSegue(withIdentifier: "showOTP", sender: data)
} else {
performSegue(withIdentifier: "showHome", sender: data)
}
}
這裏我用data
作爲sender
參數。請將其替換爲您要發送到其他視圖控制器的數據。
然後,覆蓋prepareForSegue
:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showOTP" {
let vc = segue.destination as! OTPController // Here replace OTPController with the class name of the OTP screen
vc.username = sender as! String // username is a property in OTPController used to accept the value passed to it. If you don't have this, declare it.
} else if segue.identifier == "showHome" {
let vc = segue.destination as! HomeController // Here replace HomeController with the class name of the home screen
vc.data = sender as! SomeType // data is a property in HomeController used to accept the value passed to it. If you don't have this, declare it.
// replace SomeType with the type of data you are passing.
}
}
您使用的故事板? – Sweeper
是的,我用故事板現在... – Sam
可以使用SEGUE去不同的屏幕和給每一個Segue公司標識。 –