MultipleViewsViewController.h должен быть:
#import <UIKit/UIKit.h>
@class FirstViewController;
@class SecondViewController;
@class ThirdViewController;
@interface MultipleViewsViewController : UIViewController {
IBOutlet FirstViewController *firstViewController;
IBOutlet SecondViewController *secondViewController;
IBOutlet ThirdViewController *thirdViewController;
}
//@property (nonatomic, retain) FirstViewController *firstViewController;
//@property (nonatomic, retain) SecondViewController *secondViewController;
//@property (nonatomic, retain) ThirdViewController *thirdViewController;
-(IBAction)loadFirstView:(id)sender;
-(IBAction)loadSecondView:(id)sender;
-(IBAction)loadThirdView:(id)sender;
@end
MultipleViewsViewController.m должно быть:
#import "MultipleViewsViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
@implementation MultipleViewsViewController
//@synthesize firstViewController;
//@synthesize secondViewController;
//@synthesize thirdViewController;
-(IBAction)loadFirstView:(id)sender{
[secondViewController.view removeFromSuperview];
[thirdViewController.view removeFromSuperview];
[self.view insertSubview:firstViewController.view atIndex:0];
}
-(IBAction)loadSecondView:(id)sender{
[firstViewController.view removeFromSuperview];
[thirdViewController.view removeFromSuperview];
[self.view insertSubview:secondViewController.view atIndex:0];
}
-(IBAction)loadThirdView:(id)sender{
[firstViewController.view removeFromSuperview];
[secondViewController.view removeFromSuperview];
[self.view insertSubview:thirdViewController.view atIndex:0];
}
-(void)dealloc{
[firstViewController release];
[secondViewController release];
[thirdViewController release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
thirdViewController = [[ThirdViewController alloc] init];
[self loadFirstView:nil];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
Соедините свои кнопки (что вы не сделали в своем проекте, что также может быть проблемой), и все готово.