[英]Transition without loose data with Storyboard and Swift
I'm developing a new project in Swift but i've a big (and dumb) problem. 我正在用Swift开发一个新项目,但是我遇到了一个很大的问题。
I've three viewControllers: 我有三个viewControllers:
1.- Call webservices, take JSON and pass this JSON to the second view 1.-调用Web服务,获取JSON并将此JSON传递到第二个视图
2.- Parsing data and put the data in the view (tableview and everything ok). 2.-解析数据并将数据放入视图中(tableview,一切正常)。 At this view I go to other view with a button (to the view 3). 在此视图下,我使用一个按钮转到另一个视图(到视图3)。 I don't need pass nothing. 我什么也不需要通过。
3.- I try to go back to view 2 but the view is empty because the data who posicioning at the tableview was pass from view 1. 3.-我尝试返回到视图2,但是视图为空,因为在表视图中定位的数据是从视图1传递的。
I try with a lot of solutions: 我尝试了很多解决方案:
navigationController!.dismissViewControllerAnimated(false, completion: nil) -> If i link the storyboard with a transition from view 3 to view 2, the view 2 is empty, if i don't link in storyboard -> unexpectedly found nil while unwrapping an Optional value navigationController!.dismissViewControllerAnimated(false,complete:nil)->如果我将情节提要链接到从视图3到视图2的过渡中,则视图2为空,如果我未在情节提要中链接->展开包装时意外发现nil可选值
If i change "!" 如果我更改“!” for "?" 为“?” do nothing 没做什么
The same with every code i have been test. 我测试过的每个代码都一样。
My code is: 我的代码是:
View 1 to view 2: (connected in the visual part of Storyboard (IB)) 视图1到视图2 :(在情节提要(IB)的可视部分中连接)
@IBAction func goRecibosPendientes(sender: UIButton) {
let controllerVC = self.storyboard!.instantiateViewControllerWithIdentifier("recibos") as! TablaRecibosTableViewController
controllerVC.initWithJSON(self.jsonReceived)
self.presentViewController(controllerVC, animated: true, completion: nil)
}
View 2 to View 3: (connected in the visual part of Storyboard (IB)) 视图2到视图3 :(在情节提要(IB)的可视部分中连接)
@IBAction func goToTablaProveedoresDeServicios(sender: UIButton) {
let controllerVC = self.storyboard!.instantiateViewControllerWithIdentifier("proveedoresDeServicios") as! TablaProveedoresDeServicios
self.presentViewController(controllerVC, animated: true, completion: nil)
}
View 3 to 2: I try every kinds of do that (every kinds i know, not EVERY kinds) 视图3到2:我尝试各种方法(我知道的每种方法,不是每种方法)
@IBAction func backPressed(sender: UIButton) {
navigationController!.dismissViewControllerAnimated(false, completion: nil)
navigationController!.dismissViewControllerAnimated(true, completion: nil)
navigationController!.popToRootViewControllerAnimated(true)
}
Thanks a lot. 非常感谢。
如果您使用NavigationController
不是尝试push
视图控制器,它将保留您先前的视图在堆栈中。
self.navigationController.pushViewController(controllerVC, animated: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.