我有两个viewcontrollers在swift中自定义'push'Segue。当我在tableview中选择一行时,它完美地显示了一个包含三个选项的警告框。我的问题是当我选择第一个选项(Ver Mapa)更改为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;
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 :(得分:1)
你的代码搞砸了。
显示提醒的代码不属于prepareForSegue
。您不应该在prepareForSegue
中执行任何用户界面。您也不应该在performSegueWithIdentifier
内拨打prepareForSegue
。在您或用户触发segue之后,系统会在显示新视图控制器之前调用prepareForSegue方法。它让你有机会进行设置。
您发布的代码不太可能显示警告。
这是你想做的事情:
如果要在用户选择表视图中的单元格时触发警报,请实施表格视图委托方法didSelectRowAtIndexPath:
。在该方法中,创建并显示警报控制器。当用户选择一个选项时,如果你想触发一个segue,你应该调用performSegueWithIdentifier。
一旦您触发了segue,系统就会调用您的prepareForSegue
方法
答案 1 :(得分:0)
在动作处理程序中,你必须调用 segue,而不是检查它。您在prepareForSegue
...
// calling the segue
self.performSegueWithIdentifier("go_to_mapa")
答案 2 :(得分:0)
我解决了它没有动画:像这样的假:
100 50 100 100
-82.5614380549815 -61.2386250164727 -70.8214933555803 -113.085294273425
63.4808523920134 71.2492107022344 40.2403909177619 123.906052225068
-43.1428254169980 -79.8465560431243 -8.86332933780633 -132.269515222896
21.9512910424390 86.8494877098212 -22.6803808332093 137.993637919124
-0.324547757386938 -92.1128384145929 53.7640196166716 -140.954822929939
-21.3110352832942 95.5328877966081 -83.7748031881502 141.094761269331
42.5230708505071 -97.0466778715188 112.116137495667 -138.418902426909
-62.8798722752104 96.6307163280550 -138.215550196187 132.992890319329
81.9803719854667 -94.2947890971016 161.559769097134 -124.926060504869
-99.4446392159052 90.0812551138450 -181.682036111080 114.372592711550
114.920836766971 -84.0716375263694 198.174987302179 -101.539954624572
-128.100385825296 76.3847285271368 -210.709163142815 86.6824352002572
138.720481894513 -67.1710769635203 219.033021842029 -70.0921219690280
-146.574502140440 56.6199063635580 -222.990477101486 52.1070327582791
151.516503440925 -44.9493339209586 222.520965582938 -33.0950981283072
-153.445319072891 32.3873778023315 -217.627693978053 13.4288556805328
152.307662312383 -19.1817679777499 208.387426508819 6.50027540164903
-148.121448302555 5.59183915228772 -194.975897304652 -26.2998808971022
140.970297553726 8.11485856302741 177.658703561865 45.5804419325655