1

I have created a view using IB in xib, loaded the view, and when I try to customize the containers (image, label, button e.t.c.) some containers are customized and some not. Like if I am setting the image on a image view it is getting set on the other hand customizing the button/label fails. I am doing all these customization in awakeFromNib method, this method is kept in view created using xib.

I tried to debug to see what's going on behind the scenes. Whenever an instance of view from xib is created awakeFromNib is called and rest of the picture is well presented by the screenshot below

/Users/sanjay/Desktop/psc2.tiff

As the screen shot shows, my code is halt by the breakpoint in awakeFromNib method and the debugger shows view is created in memory, it's subviews images are also created but label and button are nil, also used lldb to see if the things shown in debugger are correct.

Now I am not able to understand this behavior of creating a view using XIB having some containers created/ some not in awakeFromNib method, also the docs says use IBOutlets inside awakeFromNib to do any customization as the time awakeFromNib is called the view is completely created. But I guess it's not so.

Any help in decoding/ reverse engineering the above behavior of the debugging or what goes while creating a view with nib is much appreciated.

Many thanks in advance.

Sanjay Mohnani
  • 5,947
  • 30
  • 46
  • Just a quick check: do you have the `nil` outlets properly linked in IB? – Jakub Vano May 05 '15 at 11:20
  • @JakubVano yes they are, as the image views are linked the buttons and labels are also linked after few milliseconds if I see the addresses of the label and buttons they are non-nil – Sanjay Mohnani May 05 '15 at 11:26
  • Just to clarify: `titleLabel` and `okButton` are properly created, but after the `-awakeFromNib:` is being called? That is weird.. – Jakub Vano May 05 '15 at 11:35
  • @JakubVano vist this link -http://stackoverflow.com/questions/9122344/when-does-awakefromnib-get-called?answertab=oldest#tab-top – Sanjay Mohnani May 05 '15 at 11:44
  • 1
    Have you called [super awakeFromNib]? "You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require." – Danyun Liu May 05 '15 at 11:47

0 Answers0