2015-05-09 77 views
0

我有兩個視圖控制器與自定義'推'segue在迅速。當我在桌面視圖中選擇一行時,它顯示完美的三個選項的警告框。我的問題是,當我選擇第一個選項(Ver Mapa)更改爲另一個視圖控制器時,它不起作用。不做任何事情。我該如何解決它?prepareForSegue不能快速工作。我該如何解決它?

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; 
      self.performSegueWithIdentifier("go_to_mapa", sender: self) 
      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! 


     } 



    })) 
    refreshAlert.addAction(UIAlertAction(title: "Detalle Vehiculo", style: .Default, handler: { (action: UIAlertAction!) in 
     println("Detalle Vehiculo") 
    })) 
    refreshAlert.addAction(UIAlertAction(title: "Ejecutar comandos", style: .Default, handler: { (action: UIAlertAction!) in 
     println("Ejecutar comandos") 
    })) 

    refreshAlert.addAction(UIAlertAction(title: "Cancelar", style: .Default, handler: { (action: UIAlertAction!) in 
     self.back() 
    })) 

    presentViewController(refreshAlert, animated: true, completion: nil) 

} 

回答

0

你的代碼搞砸了。

顯示您的警報的代碼不屬於prepareForSegue。你不應該在prepareForSegue中做任何UI。您也不應該在prepareForSegue內撥打performSegueWithIdentifier。在您或用戶觸發了一個繼續之後,在顯示新的視圖控制器之前,系統會調用您的prepareForSegue方法。它給你一個設置的機會。

您發佈的代碼不太可能會顯示警報。

這裏是你想要做什麼:

如果要觸發用戶在表視圖中選擇的小區的警報,實現表視圖的委託方法didSelectRowAtIndexPath:。在該方法中,創建並顯示警報控制器。當用戶選擇一個選項時,那麼如果你想觸發一個選項,你應該調用performSegueWithIdentifier。

一旦你已經引發了賽格瑞系統會打電話給你的prepareForSegue方法

0

在你必須呼叫的SEGUE操作處理程序,不檢查。您檢查SEGUE在prepareForSegue ...

// calling the segue 
self.performSegueWithIdentifier("go_to_mapa") 
0

我沒有動畫解決它:假像這樣:

... 
... 
svc.Device = currentCell.detailTextLabel!.text! 
      svc.desc = currentCell.textLabel!.text! 

      self.navigationController?.pushViewController(svc, animated: false) 
+0

沒有足夠的上下文來知道這些代碼去。如果您要發佈答案,請說明您放置該代碼的方法,以及何時調用該方法。基於你原來的問題中的混亂,我打賭你需要做出更多的改變。 –

相關問題