programming
Segue로 다른 ViewController에 데이터 전달하기 (Swift 2.0)
artfrige
2016. 3. 15. 21:40
Segue를 이용해서 다른 ViewController에 데이터 전달하는 코드
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "targetSegue"){
let targetView : targetViewController = segue.destinationViewController as! targetViewController
targetView.targetVariable = thisViewControllerVariable
}
}
이쪽 뷰 컨트롤러의 thisViewControllerVariable 변수 값을 targetViewController의 targetVariable이라는 변수에 전달한다.
targetViewController에서는 targetVariable 이라는 변수를 선언하면 값은 자동으로 전달됨.