2017-02-09 1 views
0

클릭 할 때 두 가지 작업을 수행해야합니다. 메시지 표시 및 다른 사용자 인터페이스로 이동. 당신은 또한 동일한보기를 제공하려는 경우 그러나 여기에만 작업 1 실행하지만 2왜 작업 2를하고 있지 않습니까?

@IBAction func sendMessage(_ sender: AnyObject) { 

    // TASK 1 - OK  
    let alert = UIAlertController(title: "Task 1", message: "Test message.", preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))  
    self.present(alert, animated: true) 

    // TASK 2 - FAIL (does not execute) 
    let x = XyzViewController() 
    x.body = "test"; 
    self.present(x, animated: false, completion: nil) 
} 
+0

콘솔을보십시오. 문제를 알려주는 오류 메시지가 있어야합니다. – rmaddy

+0

그리고 작업 2 코드가 실행 중입니다. 디버거를 사용하여 확인하십시오. – rmaddy

답변

2

UIAlertController을 추론, 액션 내부에서 작업을 호출 할 일이 아니다 것은의 ViewController, 그것은 이미 제시되어 , 당신은 현재의 VC를 먼저 해고 할 필요가 있습니다. 그러나 여기에는 할 일이별로 없습니다.

// TASK 1 - OK  
let alert = UIAlertController(title: "Task 1", 
           message: "Test message.", 
           preferredStyle: UIAlertControllerStyle.alert) 
alert.addAction(UIAlertAction(title: "OK", style: .default) { action in 
    // perhaps use action.title here 
    let x = XyzViewController() 
    x.body = "test"; 
    self.present(x, animated: false, completion: nil) 
}) 

self.present(alert, animated: true) 
관련 문제