简体   繁体   English

IB中的子类

[英]Subclassing in IB

I have UIScrollView added to the main window of the app with IB. 我将UIScrollView添加到应用程序的主窗口中。 What I want is that view to subclass UICustomScrollView instead of UIScrollView. 我想要的是查看子类UICustomScrollView而不是UIScrollView。 To do that I choose the UIScrollView and then I change Custom class to UICustomScrollView in identity inspector. 为此,我选择了UIScrollView,然后在身份检查器中将Custom类更改为UICustomScrollView。 I have put some NSLog messages in init method of UICustomScrollView. 我在UICustomScrollView的init方法中放了一些NSLog消息。 When I run the app UICustomScrollView seem like it is not used because NSLog messages in init are not printed. 当我运行应用程序时,UICustomScrollView似乎没有被使用,因为init中的NSLog消息未被打印。

What I miss here ? 我想念的是什么?

Here's what the UIView Class Reference has to say about initWithFrame: : 以下是UIView类参考initWithFrame:说法:

If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file. 如果使用Interface Builder设计接口,则随后从nib文件加载视图对象时不会调用此方法。 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. 重构nib文件中的对象,然后使用其initWithCoder:方法进行初始化,该方法修改视图的属性以匹配存储在nib文件中的属性。

If your NSLog is only in initWithFrame , it won't be called if the view is loaded from a nib. 如果您的NSLog仅在initWithFrame ,则如果从nib加载视图,则不会调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM