Reputation: 6490
Basically, what I want to do is,
I want to load 2 different XIB files on each click of Segmented control
Is it possible to load 2 different XIB files?
for eg:
When I click on View 1
my 1st XIB should be loaded and when i click on View 2
my 2nd XIB should be loaded.
Is it possible?
Upvotes: 1
Views: 261
Reputation: 49730
you can this using xib like this bellow:-
UIView
or UIsegmentController
and connect it's IBOutLate like bellow image .In viewDidLoad
secondView put as a hidden True like bellow:-
- (void)viewDidLoad
{
myview1.hidden=FALSE;
myview2.hidden=TRUE;
[super viewDidLoad];
}
Put segment control ValueChange Action and connect with Segment control as a ValueChange:-
-(IBAction)segmentedControlIndexChanged{
switch (seg.selectedSegmentIndex) {
case 0:
myview1.hidden=FALSE;
myview2.hidden=TRUE;
break;
case 1:
myview1.hidden=TRUE;
myview2.hidden=FALSE;
break;
default:
break;
}
}
Now run you Project it's look like :)
Upvotes: 4
Reputation: 9836
If I understand your image, I can see two view within same xib. What you want to do is called load two different view from same xib.
you need to use [NSBundle loadNibNamed:owner:options:] method to achieve this.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyXIBName" owner:self options:nil];
Array nib will hold all views under given XIB. You can iterate/filter, and then load desired view on segment control click.
Upvotes: 1
Reputation: 3960
you can create two view inside the same nib/xib
file and add particular view
on click Segemented control
One view already has outlet
in controller class and for other view create a IBOutlet
and use.
Upvotes: 1