【发布时间】:2017-07-26 15:40:30
【问题描述】:
我正在尝试制作一个警报控制器,如果答案是“Ok”,那么它将对 MapView 执行 segue。完整代码如下:
@IBAction func teste(_ sender: Any) {
// Create the alert controller
let alertController = UIAlertController(title: "Reservar vaga?", message: "Uma vaga será reservada em Estapar Estacionamento.", preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(alert:UIAlertAction) -> Void in
let confirmAction = UIAlertController(title: "Vaga confirmada", message: "Gostaria de ter direções ao local?", preferredStyle: .alert)
let okConfirmAction = UIAlertAction(title:"Sim", style: UIAlertActionStyle.default, handler:{(alert:UIAlertAction) -> Void in
presentViewController(ViewController, animated: true, completion: nil)
})
let noConfirmAction = UIAlertAction(title:"Não", style: UIAlertActionStyle.default) {
UIAlertAction in
NSLog("Ok Pressed")
}
confirmAction.addAction(okConfirmAction)
confirmAction.addAction(noConfirmAction)
self.present(confirmAction, animated: true, completion: nil)
})
let cancelAction = UIAlertAction(title: "Cancelar", style: UIAlertActionStyle.cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}
// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)
//Append the button to the view
self.present(alertController, animated: true, completion: nil)
}
我在这部分遇到了麻烦:
let okConfirmAction = UIAlertAction(title:"Sim", style: UIAlertActionStyle.default, handler:{(alert:UIAlertAction) -> Void in
presentViewController(ViewController, animated: true, completion: nil)
})
当我尝试使用 presentViewController 时,出现此错误:“无法将“ViewController.Type”类型的值转换为预期的参数类型“UIViewController””
当我尝试使用 performSegue 时,我使用的是这种方式:
performSegue(withIdentifier: "teste", sender: (Any).self)
然后出现如下错误:“Implicit use of self inclosure; use 'self.'使捕获语义明确”
谁能帮帮我?
【问题讨论】:
-
我假设 ViewController 是类名,而不是类实例 - 因此问题
-
@Miknash 你能解释一下吗?我是 swift 新手:p
-
你有 ViewController 类吗?或者你有 var ViewController: MyViewController?
-
我有两个 viewController,第一个名为 ViewController(链接到我想在 segue 之后显示的地图视图)和第二个名为 ViewController2(链接到应用程序的初始视图)跨度>