I use Storyboard create a view controller,but with the code instantiation,then pass the value to the controller.
I know it will be called "initWithCoder:", but in the method the property is nil.
I get the property values form somewhere?
Pass values between the controller
39 Views Asked by RuiK At
2
There are 2 best solutions below
1
On
Let's say you have viewControllers: A (root) and B (presenting). You need to use prepareForSegue method from A viewController:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let bView = segue.destinationViewController as? BViewController{
bView.yourDataProperty = dataItem
}
}
}
Make sure your sender is presenting BViewController in Storyboard. Otherwise this method won't be called
If you are creating your view controller through a storyboard segue, use the source view controller's
prepareForSegue()method, as explained in this answer to a similar question.