Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Defined Runtime Attributes accessibility

I created a User Defined Runtime Attributes to my custom UIView in IB, and the interesting thing is, that I can access it in touchesBegan:withEvent: method but not in initWithCoder: Do you know why?

like image 410
János Avatar asked Oct 31 '12 08:10

János


2 Answers

If you need to access the values when setting up your view instead of processing it in initWithCode: use awakeFromNib

like image 168
appmattus Avatar answered Oct 20 '22 22:10

appmattus


It is because the views from IB are finished loading after initWithCoder. The following will help you understand the process. It is explained for UIViewControllers, but the concept is the same (from the ViewController Programming Guide):

When you create a view controller in a storyboard, the attributes you configure in Interface Builder are serialized into an archive. Later, when the view controller is instantiated, this archive is loaded into memory and processed. The result is a set of objects whose attributes match those you set in Interface Builder. The archive is loaded by calling the view controller’s initWithCoder: method.

like image 43
Masa Avatar answered Oct 20 '22 21:10

Masa