ログイン画面から2つのセグを接続できます。
ストーリーボードでは、ログイン画面からOTP画面にセグを接続し、ログイン画面からホーム画面にセグを接続します。ストーリーボードのコントローラからドラッグすることを覚えておいてください。コントローラ内のビューはではありません。
右パネルに各セグメントに識別子を付けます。私は最初のsegue(login - > OTP) "showOTP"と2番目のsegue(login - > home screen) "showHome"を呼び出します。
if文で
:私はsender
引数としてdata
を使用
ここ
func LoginDone() {
if (registeredUser()){
performSegue(withIdentifier: "showOTP", sender: data)
} else {
performSegue(withIdentifier: "showHome", sender: data)
}
}
。これを他のView Controllerに送信するデータに置き換えてください。
その後、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に識別子を付けることができます。 –