我正在研究出勤应用程序。有点混淆如何通过警报视图打开另一个视图控制器。
这是我的代码:
let actionSheet = UIAlertController (title: "Please Confirm Before Scan", message: messageToShow, preferredStyle: .alert)
let okAction = UIAlertAction (title: "Proceed to Scan", style: .default, handler: {action in
picker.sourceType = .camera
let cancelAction = UIAlertAction (title: "Reselect", style: .cancel, handler: nil);},
actionSheet.addAction(FourthViewController),
actionSheet.addAction(canPerformAction),
present(actionSheet, animated: true, completion: nil)
)}
当我单击“继续扫描” 并转到另一个 FourthViewController 时,我希望获得UI警报视图。
答案 0 :(得分:0)
取决于您的视图层次结构。
让我们说您想将警报操作中的视图控制器推送到当前视图控制器的导航堆栈中。在操作内部,您将必须编写用于关闭UIAlertController
的代码,然后可以将 FourthViewController 推入导航堆栈,或者如果要显示 FourthViewController < / em>,然后只需将其显示即可。
//inside the view controller presenting the alert
alertController.addAction(UIAlertAction(title: "Yo", style: .default, handler: { (action) in
DispatchQueue.main.async{
alertController.dismiss(animated: true, completion: nil)
//push or whatever by referencing self
}
}))
答案 1 :(得分:0)
您可以这样做:
let actionSheet = UIAlertController (title: "Please Confirm Before Scan", message: "messageToShow", preferredStyle: .alert)
let okaction = UIAlertAction(title: "Proceed to Scan", style: .default) { (action) in
gotoFouthViewController(/*add argument if needed*/)
}
let cancelaction = UIAlertAction(title: "Reselect", style: .cancel) { (action) in
//cancel the alert
}
actionSheet.addAction(okaction),
actionSheet.addAction(cancelaction),
present(actionSheet, animated: true, completion: nil)
//在当前控制器的某处添加此
func gotoFouthViewController(argument) {
//push or present the fourth view controller here
}