2017-05-17 12 views
0

私はIOS開発の新機能です... android背景 xcodeでログインを実装したいと考えています... ユーザがログインボタンをクリックして成功した場合、 first login OTP画面に行き、ユーザーが登録ユーザーの後に...ログインボタンをクリックするたびにホーム画面に移動する必要があります。 基本的にloginボタンをの画面に切り替える必要があります(ナビゲーションなし)画面を動的に切り替える方法

たとえば、この機能はログインが完了したときです

func LoginDone() 
{ 
    if (registeredUser()){ 
    //switch to OTP screen and also send The username to that .swift file 
    } 

    else{ 
    //switch to homescreen and send some data to that .swift file 
    }  
} 
+0

あなたはストーリーボードを使用していますか? – Sweeper

+0

はい私は現在ストーリーボードを使っています... – Sam

+0

segueを使って別の画面に行き、それぞれのsegueに識別子を付けることができます。 –

答えて

1

ログイン画面から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. 
    } 
} 
+0

助けてくれてありがとう...とてもよく説明されています – Sam

関連する問題