如何将数据从UI警报控制器传递到另一个视图控制器iOS
我正在扫描考勤应用程序。关于如何通过警报视图打开另一个视图控制器,有点混乱 这是我的代码:如何将数据从UI警报控制器传递到另一个视图控制器iOS,ios,mobile,Ios,Mobile,我正在扫描考勤应用程序。关于如何通过警报视图打开另一个视图控制器,有点混乱 这是我的代码: let actionSheet = UIAlertController (title: "Please Confirm Before Scan", message: messageToShow, preferredStyle: .alert) let okAction = UIAlertAction (title: "Proceed to Scan", style: .default, handler:
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警报视图。取决于您的视图层次结构 假设要将警报操作上的视图控制器推送到显示视图控制器的导航堆栈上。在操作中,您必须编写关闭
UIAlertController
的代码,然后您可以将FourthViewController推到导航堆栈上,或者如果您想显示FourthViewController,只需显示它即可
//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
}
}))
您可以这样做:
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
}
第二栏“当前控制器中的某处”是否为第四视图控制器?抱歉,我在这方面有点困惑:)不,这是显示操作表的控制器。@fnsmp答案对您有帮助吗?