0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
RuiK
  • 3
  • 2

2 Answers2

0

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.

Community
  • 1
  • 1
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
0

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

Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
  • https://www.dropbox.com/s/o3qdmb6ktuayl13/CoderDemo.zip?dl=0 This is an example of address – RuiK Nov 10 '15 at 09:13