I have 3 separate view controllers with their own NIB file.
I have a overview view in my app with a segmented control that you can toggle through. Instead of copying all 3 of these view's methods and putting them into this overview's class, is it possible to just load each view as a subview of the overview view deepening on which segment is selected?
- (void)segmentedControl:(SVSegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)index
{
switch (index)
{
case 0:
{
MusclesTableViewController *musclesTableViewController = [[MusclesTableViewController alloc] initWithNibName:@"MusclesTableViewController" bundle:nil];
[self.view addSubview: musclesTableViewController];
[musclesTableViewController release];
}
break;
case 1:
// load second nib and add it a开发者_JAVA百科s a subview
break;
default:
break;
}
}
Connect an action to your segment controller:
[yourSegmentedControl addTarget:self action:@selector(changeSegment:) forControlEvents:UIControlEventValueChanged];
use your method to load the desired subview:
- (void)changeSegment:(id)sender {
UISegmentedControl *segment = sender;
switch ([segment selectedSegmentIndex]) {
case 1:
// load first nib and add it as a subview
break;
case 2:
// load second nib and add it as a subview
break;
default:
break;
}
}
精彩评论