开发者

How to load a view XIB as a subview into a view controller XIB

I have a custom view I made with an IB file since it's quite complex: (RotatorView.xib/.h/.m). I want to add the RotatorView as a subview to a view controller. I can do this programmatically using:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"RotatorView" 
                                               owner:self options:nil];

But I'd rather not do that. It would be better for my design if I could add the RotatorView to the canvas of a View Controller in Interface Builder. That way I could use IB to manage the properties of each instance of RotatorView instead of setting properties programmatically in each class. Is there a way that I can add my custom view with XIB to a parent view controller? 开发者_如何学JAVA Do I have to build an IB plugin to do this?


You can add a UIView control to the canvas in IB and change its class name to match your custom view class name. Although this will save you from calling loadNibNamed method programmatically, but you'll not be able to set the custom properties directly from IB.

The only solution for doing this is to build an IB plugin, but unfortunately it seems you can't make Cocoa Touch IB plugins because you can't make Cocoa Touch frameworks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜