You don't need to define initWithCoder, since you have no custom logic in there. I would delete that boilerplate code.
Here is what I would check:
- In the storyboard, ensure that the class of the view controller is set properly.
- Ensure that the outlet is hooked up properly in the storyboard by looking for a circle near your @property. It should be a filled in circle, not an outline of a circle.
- Make sure you are reading the value only after viewDidLoad is called. Apple's only guarantee is that the outlet is set after this method call.
Update: It sounds like you want to access the image view before the view is loaded. There is no way to do this. One hack is to call viewController.view
which will force the view to load, but there are many reasons why you should not do this.
A better approach would be to implement properties on your view controller which work for both when the view is not loaded and when the view is loaded. You can see an example of an elegant solution in this question. Notice how if the view is loaded, the photographerLabel
will get set via the didSet
method. On the other hand, if the view is not loaded, it will get set via the viewDidLoad
method. For an Objective-C version of that code or for more details, see the linked video in that question.