【发布时间】:2019-02-06 12:15:58
【问题描述】:
我正在尝试在确认警报后移至下一个 ViewController。
@IBAction func yesBtn(_ sender: Any) {
let dialogMessage = UIAlertController(title: "Confirm", message: "Are you sure?", preferredStyle: .alert)
let ok = UIAlertAction(title: "Confirm", style: .default, handler: { (action) -> Void in
print("Ok button tapped")
self.saveRecord(Answer: "yes")
CATransaction.setCompletionBlock({
self.performSegue(withIdentifier: "mainUse", sender: nil)
})
})
let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
print("Cancel button tapped")
}
//Add OK and Cancel button to dialog message
dialogMessage.addAction(ok)
dialogMessage.addAction(cancel)
// Present dialog message to user
self.present(dialogMessage, animated: true, completion: nil)
}
在情节提要上添加转场后,我设法执行转场,但是这会执行转场两次,一次是在按下是按钮时,另一次是在警报框中确认时。如果我删除情节提要上的转场,则根本不会执行转场。我还尝试通过将按钮拖动到下一个视图控制器然后选择custom 而不是show 来创建自定义segue,但这会产生SIGABRT 错误。显然,在警告框中按下确认后,它应该只进行一次。
我在网上发现了类似的问题,但大多数似乎都错过了故事板的部分,我应该在两个视图之间建立链接还是应该全部以编程方式完成?如果仅以编程方式完成,我应该如何识别下一个视图控制器?
【问题讨论】:
-
确保您的
yesBtn直接在 segue 中连接