无法更改为具有多个segue的另一个视图控制器。我该如何解决?

时间:2015-05-09 15:34:10

标签: ios iphone uitableview swift swiftmailer

我在swift中使用了多个segue,而UIAlertView中有一个tableViewUIAlertView显示完美。当我点击第一个选项(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)
}   

1 个答案:

答案 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
    }
}