Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView's initWithFrame not working?

Tags:

iphone

i set my view controller to the particular view through Interfacebuilder. but initWithFrame is not calling , but drawRect is being called?when i put break point?

like image 419
senthilM Avatar asked Oct 21 '09 11:10

senthilM


2 Answers

Right, because it's not guaranteed that initWithFrame: will be called when unarchiving the xib. Try using awakeFromNib or viewWillLoad or viewDidLoad. Which one you choose will mainly depend on at what stage during the display process you need to insert your code.

Also, check out the answer to this question.

like image 79
G Gordon Worley III Avatar answered Oct 01 '22 14:10

G Gordon Worley III


According to the documentation - http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html - initWithFrame: is not called when your view objects are subsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file.

like image 44
Christian Fries Avatar answered Oct 01 '22 15:10

Christian Fries