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.
}
당신은 또한 문제가 될 수있는 프로젝트에 수행하지 않은 당신의 버튼 (연결) 그리고 끝났어.