我在swift中使用了多个segue,而UIAlertView
中有一个tableView
。 UIAlertView
显示完美。当我点击第一个选项(Ver Mapa)时,它会与segue(viewController
)完美地改变为另一个go_to_mapa
(Mapa)。但是当我按下第二个选项(Ver detalle)并使用segue(go_to_detalle
)更改为anotherViewController
时,它不起作用。什么都不做。我该怎么解决呢?
override func prepareForSegue(segue: (UIStoryboardSegue!), sender: AnyObject!) {
var refreshAlert = UIAlertController(title: "Menu", message: "Seleccione una opcion", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Ver Mapa", style: .Default, handler: { (action: UIAlertAction!) in
if (segue.identifier == "go_to_mapa") {
var svc = segue!.destinationViewController as Mapa;
svc.cuenta = self.cuenta
svc.user = self.user
svc.password = self.password
let indexPath = self.tableView.indexPathForSelectedRow();
let currentCell = self.tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
svc.Device = currentCell.detailTextLabel!.text!
svc.desc = currentCell.textLabel!.text!
self.navigationController?.pushViewController(svc, animated: false)
}
}))
refreshAlert.addAction(UIAlertAction(title: "Ver Vehiculo", style: .Default, handler: { (action: UIAlertAction!) in
if (segue.identifier == "go_to_detalle") {
let vc = segue.destinationViewController as Detalle_Vehiculo
}
}))
refreshAlert.addAction(UIAlertAction(title: "Ejecutar comandos", style: .Default, handler: { (action: UIAlertAction!) in
println("Ejecutar comandos")
}))
presentViewController(refreshAlert, animated: true, completion: nil)
}
答案 0 :(得分:0)
prepareForSegue:
会调用shorty。来自doc:
通知视图控制器即将执行segue。
因此,您不应该在该方法中显示任何警报,弹出窗口。相反,您应该在展示之前采取destinationViewController
并进行适当调整。
相反,您应该在tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
中显示警告,如下所示:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var refreshAlert = UIAlertController(title: "Menu", message: "Seleccione una opcion", preferredStyle: UIAlertControllerStyle.Alert)
refreshAlert.addAction(UIAlertAction(title: "Ver Mapa", style: .Default, handler: { (action: UIAlertAction!) in
self.performSegueWithIdentifier("go_to_mapa", sender:self)
}))
refreshAlert.addAction(UIAlertAction(title: "Ver Vehiculo", style: .Default, handler: { (action: UIAlertAction!) in
self.performSegueWithIdentifier("go_to_detalle", sender:self)
}))
refreshAlert.addAction(UIAlertAction(title: "Ejecutar comandos", style: .Default, handler: { (action: UIAlertAction!) in
println("Ejecutar comandos")
}))
presentViewController(refreshAlert, animated: true, completion: nil)
}
准备它:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "go_to_mapa" {
var svc = segue!.destinationViewController as Mapa
svc.cuenta = self.cuenta
svc.user = self.user
svc.password = self.password
let indexPath = self.tableView.indexPathForSelectedRow();
let currentCell = self.tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
svc.Device = currentCell.detailTextLabel!.text!
svc.desc = currentCell.textLabel!.text!
}
else if segue.identifier == "go_to_detalle" {
let vc = segue.destinationViewController as Detalle_Vehiculo
}
}