Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ios single xib with multiple views

Tags:

ios

xib

I've noticed that i can put in a single xib multiples UIView; the main view is associated with the file's owner, but how to reference other views in the xib?

My need: i've a xib view splitted with a fixed top part and a bottom part made by a tabbar with three tab buttons: by clicking each button i need to load a subview, so my idea is to put other sub-views in the same xib on other views and load them on demand. How to accomplish this? Thanks

like image 204
ʞᴉɯ Avatar asked Jul 03 '13 21:07

ʞᴉɯ


1 Answers

You can just create IBOutlets in your header files and associate them with the additional views, just like any other Interface Builder component (or even just ctrl-click and drag your views to your code, if you're working in XCode's automatic assistant mode).

For example, let's say you have a view controller called FooViewController, and a matching FooViewController.xib interface file:

@interface FooController : UIViewController 

@property (nonatomic, retain) IBOutlet UIView *additionalView;

@end

...and then you can just connect your additional view up to its corresponding outlet (which will appear in IB under the file owner). It's really no different to hooking up a UILabel or UIButton.

One thing to note though - you say "my idea is to put other sub-views in the same xib on other views and load them on demand". All the views inside your XIB file will actually get created at the same time, so it's not really loading on-demand. I doubt, unless you're doing something crazy, that this will be an issue for you in practice.

like image 83
lxt Avatar answered Sep 19 '22 14:09

lxt