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
use
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
[view1 addSubview:[nibContents objectAtIndex:0]];
in place of
view1 = [nibContents objectAtIndex:0];
我知道有两种可能性1.你在哪里将子视图添加到主视图2.在 - >目标 - >构建阶段 - >包含你的xib文件
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.