我正在启动一个具有两个视图的多视图应用程序:NewGame 和 Players。我以为我正在正确设置所有内容,但显然不是。
主视图控制器.h
#import <UIKit/UIKit.h>
@class NewGame; @class Players;
@interface MainViewController : UIViewController {
IBOutlet NewGame *newGameController;
IBOutlet Players *playersController;
}
-(IBAction) loadNewGame:(id)sender;
-(IBAction) loadPlayers:(id)sender;
-(void) clearView;
@end
主视图控制器.m
#import "MainViewController.h"
#import "NewGame.h"
#import "Players.h"
@implementation MainViewController
-(IBAction) loadNewGame:(id)sender {
[self clearView];
[self.view insertSubview:newGameController atIndex:0];
}
-(IBAction) loadPlayers:(id)sender {
[self clearView];
[self.view insertSubview:playersController atIndex:0];
}
-(void) clearView {
if (newGameController.view.superview) {
[newGameController.view removeFromSuperview];
} else if (playersController.view.superview) {
[playersController.view removeFromSuperview];
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[self loadNewGame:nil];
[super viewDidLoad];
}
几张图...
http://i.stack.imgur.com/GwXMa.png http://i.stack.imgur.com/XHktH.png