2016-10-16 8 views
0

セグの準備と巻き戻しの準備の違いは何ですか?私はこれらの両方をXcodeプロジェクトに実装しており、両方とも同じ結果が出ています。私はこれらの機能の両方を実装しているコードは、次のとおり(アンワインドするための準備で)セグの準備とアンワインドの準備の違い - スウィフト3.0

override func prepare(for unwind: UIStoryboardSegue, sender: Any?) { 

    let variableUnwind = ("StackOverFlow") 

    if unwind.identifier == "toFirstViewController" { 

     let hello = unwind.destination as! ViewController 

     hello.username = textField.text! 

     print(hello.username) 



    } 

} 

と:(アンワインドするための準備で)

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

     let variableUnwind = ("StackOverFlow") 

     if segue.identifier == "toFirstViewController" { 

      let hello = segue.destination as! ViewController 

      hello.username = textField.text! 

      print(hello.username) 



     } 

    } 

答えて

3

それらがどちらも同じ方法。パラメータ名がunwindまたはsegueであるかどうかは関係ありません。セレクタはprepare(for:sender:)です。 'prepare(for:送信者:)'の再宣言が無効です。と2番目のものが同じクラスに実装されています。

私はprepare(for segue: UIStoryboardSegue, sender: Any?)を使用することをお勧めします.1)それは自動完成が示唆するものであり、2)すべてのセグは、巻き戻すだけでなく通過するからです。したがって、パラメータがsegueと呼ばれるのは理にかなっています。

+0

ありがとうございました。だから、違いはなく、いずれかを選択する利点はないことを明確にするために? –

+1

ありがとうございました。私はそれに私のコードを変更します。 :-) –