gpt4 book ai didi

ios - prepareForSegue 不能快速工作。我该如何解决?

转载 作者:行者123 更新时间:2023-11-29 02:02:50 24 4
gpt4 key购买 nike

我有两个 View Controller ,可以快速自定义“推”Segue。当我在表格 View 中选择一行时,它完美地向我显示了一个带有三个选项的警报框。我的问题是,当我选择第一个选项(Ver Mapa)更改为另一个 View Controller 时,它不起作用。不做任何事情。请问如何解决?

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)

}

最佳答案

你的代码困惑了。

显示警报的代码不属于 prepareForSegue。您不应在 prepareForSegue 中执行任何 UI。您也不应该在 prepareForSegue 中调用 performSegueWithIdentifier。在您或用户触发 segue 之后,在显示新 View Controller 之前,系统会调用您的 prepareForSegue 方法。它让您有机会进行设置。

您发布的代码不太可能显示警报。

这是您想要执行的操作:

如果您想在用户选择 TableView 中的单元格时触发警报,请实现 TableView 委托(delegate)方法 didSelectRowAtIndexPath:。在该方法中,创建并显示您的警报 Controller 。当用户选择一个选项时,如果你想触发一个 segue,那么你应该调用 performSegueWithIdentifier。

一旦你触发了一个 segue,系统将调用你的 prepareForSegue 方法

关于ios - prepareForSegue 不能快速工作。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30140807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com