我想我找到了解决方案:
首先将您的视图基础应用程序更改为基于导航的:
这是您的主要笔尖的标准模板:
像这样:
添加一个 UINavigationController。打开它并将 ViewBasedViewController 拖到 UINavigationController 中的现有控制器上。
转到您的应用代理:
@interface ViewBasedAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end
@synthesize window;
@synthesize navController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
//Other code omitted
@end
将 navController 插座链接到 NIB 中的导航控制器。
使用“TheTabBarController”创建一个新类。
将此添加到基于视图的控制器以添加第五个控制器:
- (IBAction) addFifthView:(id)sender {
TheTabBarController *conn = [[TheTabBarController alloc] init];
[self.navigationController pushViewController:conn animated:YES];
[conn release];
}
像这样实现 TheTabBarController:
@interface TheTabBarController : UITabBarController {
}
@end
@implementation TheTabBarController
- (void) viewDidLoad {
UIViewController *dummy = [[UIViewController alloc] initWithNibName:@"Dummy" bundle:nil];
dummy.title = @"Dummy title";
dummy.view.backgroundColor = [UIColor redColor];
UIViewController *otherDummy = [[UIViewController alloc] initWithNibName:@"Dummy" bundle:nil];
otherDummy.title = @"Other dummy";
otherDummy.view.backgroundColor = [UIColor blueColor];
[self setViewControllers:[NSArray arrayWithObjects:dummy,otherDummy,nil]];
[dummy release];
[otherDummy release];
}
//Other code omitted
@end
应该像这样工作。