2017-04-25 27 views
-1

この文字列値を別のviewControllerに渡す必要があります。何らかの理由で、私はsigabrtエラーが発生しています。誰かが間違っていることを指摘できますか?渡す文字列Segue Swift

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "profileTapped" { 
     if let destination = segue.destination as? MyDestinationViewControllerType { 
      destination.myVariable = myClassLevelVariable 
     } 
    } 
} 
+0

に[ビューコントローラ間でデータを受け渡す]の可能な複製を追加する方法を実装する必要があり(http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – pableiros

答えて

4

のViewController userCellTappedにuserIdentityString値を渡す必要があります方法

destinationUID.performSegue(withIdentifier: "profileTapped", sender: userIdentityString) 

あなたは識別子"profileTapped"のSegueをストーリーボードに追加する必要があります。 メソッド内の送信者は、渡す値です。 識別子として、そのSegueのIDを渡す必要があります。

そして、そのコントローラにいくつかのデータを渡したい場合。前年比では

func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "profileTapped", let vc = segue.destination as? UserCellTapped, let variable = sender as? String { 
     vc.programVar = variable 
    } 
} 
0

呼び出すために:

が正しく先ビュー・コントローラ変数を設定する方法は、あなたのViewControllerクラスでprepare(for segue ...)を実装することである

class GeneralChatroom: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate { 


//Get Data of current cell that has been tapped 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ 

      //Eliminate highlight after cell is tapped 
      tableView.deselectRow(at: indexPath as IndexPath, animated: true) 

      let userIdentityString : String = generalRoomDataArr[indexPath.row].cellUserId 

      let destinationUID = userCellTapped() 

      destinationUID.programVar = userIdentityString 

      destinationUID.performSegue(withIdentifier: "profileTapped", sender: self) 


     } 

} 


    import UIKit 

    class userCellTapped: UIViewController { 

     var programVar : String! 


     override func viewDidLoad() { 
      super.viewDidLoad() 


      print("testbles", programVar) 


     } 


    } 
+0

ありがとうございました。)あなたは非常に感謝しています。 – codechicksrule

関連する問題