Reputation: 953
I am working on the iOS app but I need help with showing more custom views from xib files inside one view.
What I need is something like this:
You can see one root view, some labels and 3 custom subviews. Each subview has its own xid file but I don't know how to show them one next to each other.
I put there three views in interface builder and I thought that I just create three UIView outlets and I initialize them with loadNibName method but it doesn't work. Here is a code from controller:
@interface ViewController_iPad () {
__strong IBOutlet UIView *view1;
__strong IBOutlet UIView *view2;
__strong IBOutlet UIView *view3;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
view1 = [nibContents objectAtIndex:0];
nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView2" owner:self options:nil];
view2 = [nibContents objectAtIndex:0];
nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView3" owner:self options:nil];
view3 = [nibContents objectAtIndex:0];
}
With this code subviews are empty and contain from xib files doesn't show.
Can you tell me what I am doing wrong? Or if is it a good way how to do that? Should I use some container instead subviews? Than you
Upvotes: 1
Views: 560
Reputation: 2270
There are two possibility as fa as i know 1. Where do you add you sub views to main view 2. In ->Target -> Build Phase -> your xib files are included
Upvotes: 0
Reputation: 4953
use
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
[view1 addSubview:[nibContents objectAtIndex:0]];
in place of
view1 = [nibContents objectAtIndex:0];
Upvotes: 3