It seems that you've already answered your own question in the paragraph before edit.
The documentation states that
When an object receives an awakeFromNib message, it is guaranteed to have all its outlet instance variables set.
So if you have to access IBOutlet
ivars in your initialisation code, you have to do it in the awakeFromNib
method.
Although I prefer initWithCoder:
in cases when I do not need to access outlets because it is the proper initialiser method for objects being decoded with NSCoding
protocol according to NSCoding
documentation:
initWithCoder: instructs the object to initialize itself from data in the coder provided; as such, it replaces any other initialization method and is sent only once per object
As a side note though, it does not make much of a difference and in cases when I have to access outlets in my initialization code, I do not implement both awakeFromNib
and initWithCoder:
for the sake of simplicity. So if outlets are involved I usually implement awakeFromNib
and do all the initialisation there.