uinavigationcontroller - navigationController!.pushViewController vs. presentViewController in iOS Swift -
what implications of pushing viewcontroller in uinavigation vs. presenting viewcontroller modally in terms of changing values in next view?
for example, why first work not second?
first:
var textcontroller: textviewcontroller textcontroller = self.storyboard!.instantiateviewcontrollerwithidentifier("textviewcontroller") as! textviewcontroller presentviewcontroller(textcontroller, animated: false, completion: nil) textcontroller.textdetail.text = categories[indexpath.row]
second:
var textcontroller: textviewcontroller textcontroller = self.storyboard!.instantiateviewcontrollerwithidentifier("textviewcontroller") as! textviewcontroller self.navigationcontroller!.pushviewcontroller(textcontroller,animated:true) textcontroller.textdetail.text = categories[indexpath.row]
i can't label's value change when pushing in navigation stack.
it appears though when calling presentviewcontroller
method, view of view controller loaded during call, whereas when calling pushviewcontroller
on navigation controller, view loaded after call.
you can test printing console before , after presenting/pushing view controller, , printing console in textviewcontroller's viewdidload
method.
the view needs loaded textdetail
variable load (you haven't said so, i'm assuming iboutlet) , textdetail
variable needs load able modify text
property.
to use pushviewcontroller
example set variable on textviewcontroller
class, , override viewdidload
method, set text property on textdetail
variable.
Comments
Post a Comment