简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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