Loading another NIB into one subview of a UIVIEW
I have a simple question that I couldn't see it answered on the whole site,
One XIB file that has a UIView as the main,
in it has another UIView that's connected to one IBoutlet so I can assign it later to load a view from another XIB file. That assignment doesn't work.. it remains blank...
@interface Subclass : UIViewController {
UIView *view1;
}
@property (nonatomic,retain) IBOutlet UIView *view1;
@end
i linked view1 to the subview in the xib file in implementation in initWithNibName I'm loading Other XIB file and use it's view and assigning it to the view1. Still this doesn't work...
detailControler = [[XibViewControler alloc] initWithNibName:@"XibViewControler" bundle:nil];
//one aproach
[self.view1 addSubview: detailControler.view];
//another aproach
[self setView1:detailControler.view];
If I'm adding the subview programaticaly to [self.view addSubview:detailControler.view] a开发者_运维技巧nd set a frame to it, it will go fullscreen, and hide the original view.
I also had a different approach that didn't work How to load multiple views on each button tap when using a UISegmentedVIew
This is how I usually set up a UIView
inside another view, although I'm not entirely sure if it's best practice or anything like that:
if(newViewController == nil){
newViewController = [[NewViewController alloc] initWithCoder:nil];
}
newViewController.view.autoresizingMask = UIViewAutoresizingNone;
if([newViewController.view superview] == nil){
[view1 addSubview:newViewController.view];
}
Hope that Helps!
精彩评论