2015-05-09 41 views
-1

我在swift中使用多個segue,在tableView中我有一個UIAlertViewUIAlertView完美展現。當我點擊第一個選項(Ver Mapa)時,它完全改變爲另一個viewController(Mapa)與segue(go_to_mapa)。但是當我按賽格(go_to_detalle)將第二個選項(Ver detalle)更改爲anotherViewController時,它不起作用。不做任何事情。我該如何解決它?不能更改爲具有多個segue的另一個視圖控制器。我該如何解決它?

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

prepareForSegue:在呈現新的控制器之前調用shorty。從文檔:

通知視圖控制器即將執行一個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 
    } 
} 
+0

它顯示在地圖上的viewController的錯誤,因爲我的一些數據傳遞到地圖view controller –

+0

如果你刪除了所有實際導航到其他'otherviewcontroller'的代碼,怎麼會這樣呢?請確保您沒有'tableView:didSelectRowAtIndexPath:'也沒有'prepareForSegue:sender:'實現,並且在您點擊表格行時沒有任何反應。如果仍然發生,請刪除所有代碼 – Azat

+0

我已經刪除了所有內容,但仍然沒有發生任何事情 –

相關問題