한 컨트롤러에서 다른 컨트롤러로 데이터를 전달하려고합니다. 다음 코드는Swift 3보기 컨트롤러간에 데이터 전달
첫번째 뷰 컨트롤러 :
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let parameters: Parameters = [
"x": 2,
"y": 2
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default).responseJSON { response in
if((response.result.value) != nil) {
let jsonVar: JSON = JSON(response.result.value ?? "success")
let destViewController : JSONResult = segue.destination as! JSONResult
let result = "\(jsonVar)"
destViewController.textLabel = result
print(result)
//self.jsonDisplayError.text = "\(jsonVar)"
} else {
self.jsonDisplayError.text = "no response"
}
}
}
번째 뷰 컨트롤러 :
@IBOutlet var jsonResult: UILabel!
var textLabel = String()
override func viewDidLoad() {
jsonResult.text = textLabel
}
결과 올바르게 콘솔에 프린트되고 있지만,이 레이블에 표시되지 두 번째보기 컨트롤러 페이지.
viewwillappaer에서 jsonResult.text를 설정할 때 작동하는지 확인 했습니까? – ocanal
그 방법을 잘 모르겠습니다. – Dexstrum
[보기 컨트롤러간에 데이터 전달] 가능한 복제본 (http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers). 일부 답변은 Swift에 대한 답변입니다. like [this] (http://stackoverflow.com/a/31934786/5175709) one – Honey