2016-12-29 1 views
1

나는 에 TableViewController을 삽입했습니다. 내 UITableView에는 토글이 있습니다. 이 토글 중 하나를 토글 할 때 ViewController에 내 번호가 1 씩 증가해야합니다. 문제는 내가 바꿀 텍스트를 가져올 수 없다는 것입니다. 더 잘 설명 할 수 있도록 스크린 샷을 제공했습니다.포함 된 TableViewController에서 데이터 전달하기

enter image description here

내가 토글을 전환 할 때이 colorViewController?.displayNumber.text = screenCount을 사용하는 텍스트를 설정하려고 다음 TableViewController에서 변수 var colorViewController: ViewController?를 설정하고 일을 시도했다. screenCount은 토글이 토글 될 때 증가하는 변수입니다.

+0

, 당신은 이러한 방법 중 하나를 사용한다 :

그런 다음 (이 3 코드 스위프트입니다) 당신의 ViewController이 SEGUE을 처리 싱글, 프로토콜 또는 블록. – SNarula

답변

0

colorViewController 변수를 어떻게 설정합니까?

ViewController의 segue 준비에서 현재 ViewController 인스턴스로 설정해야합니다.

먼저 embed segue에 식별자를 제공해야합니다. 스토리 보드에서 세그먼트를 선택하고 식별자 (예 : ColorPickerTableViewControllerSegue)를 지정합니다. 당신이 이전의 ViewController에의 ViewController에서 데이터를 전달하려면

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

    if segue.identifier == "ColorPickerTableViewControllerSegue" { 
     if let colorPickerTableViewController = segue.destination as? ColorPickerTableViewController { 
      colorPickerTableViewController.colorViewController = self 
     } 
    } 
} 
관련 문제