5

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?

4

2 回答 2

11

如果您需要在设置视图而不是在initWithCode:使用中处理它时访问这些值awakeFromNib

于 2012-11-01T01:45:55.070 回答
5

这是因为来自 IB 的视图在initWithCoder. 以下将帮助您了解该过程。它被解释为UIViewControllers,但概念是相同的(来自ViewController Programming Guide):

当您在故事板中创建视图控制器时,您在 Interface Builder 中配置的属性将被序列化为存档。稍后,当视图控制器被实例化时,这个存档被加载到内存中并被处理。结果是一组对象,其属性与您在 Interface Builder 中设置的属性相匹配。通过调用视图控制器的 initWithCoder: 方法来加载存档。

于 2012-10-31T08:32:24.313 回答