2017-04-25 11 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 제대로 대상 뷰 컨트롤러 변수를 설정하여 ViewController 클래스 prepare(for segue ...)을 구현하는 것입니다 수있는 방법을 전달하는 방법

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

:

필요는

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