【发布时间】:2021-08-13 04:43:18
【问题描述】:
当我在ViewController2 中performSegue 然后在ViewController1 中自动调用unwindToMyHours。
那么我不知道为什么 X Code 会跳过呈现Alert BOX 的代码。
OUTPUT -> 其他部分完成。
和 xCode 跳过 -> Task 1 和 task 2
~ViewController2的代码
@IBAction func CancelButtonTapped(_ sender: UIButton) {
let alert = UIAlertController(title: "Delete Time", message: "Are you sure?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { [self] _ in
self.deleted = true
self.performSegue(withIdentifier: "unwindToMyHours", sender: nil)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
~ViewController1的代码
@IBAction func unwindToMyHours( _ seg: UIStoryboardSegue) {
if (seg.source as? ViewController2)?.submitted == true {
loadData()
} else if (seg.source as? ViewController2)?.deleted == true {
let alert = UIAlertController(title: "Deleted", message: "Tabel have been updated", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { alert in
print("Task 1")
}))
present(alert, animated: true) {
print("Task 2")
}
print("Else part complete")
}
}
【问题讨论】:
标签: swift xcode segue uialertview uialertcontroller