好的,这会很长:
在AppDelegate.h
分配一个UITabBarController一个UINavigationController和2个UIViewControllers
例如:
UITabBarController *mainTabBar;
UINavigationController *navController;
UIViewController *firstViewController;
UIViewController *secondViewController;
然后移动到 AppDelegate.m 并像这样实例化这 4 个项目中的每一个:
mainTabBar = [[UITabBarController alloc] init];
firstViewController = [[firstView alloc] init];
对两个视图都这样做
那么如果你想设置任何一个视图的标题,(这将是显示在标签栏中的标题)按如下方式进行:
firstViewController.title = @"Welcome";
然后为其中包含UITableView 的视图创建UINavigationController,如下所示:
navController = [[UINavigationController alloc] init];
[navController pushViewController:firstViewController animated:NO];
现在你有一个UIViewController 和一个UINavigationController,里面有一个UIViewController。
剩下的就是把你的两个标签放到UITabBarController:
mainTabBar.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];
然后只需将标签栏控制器放在屏幕上,您就可以开始了:
[window addSubview:mainTabBar.view];
要记住的几件事:
- 确保释放调用 alloc 的所有内容,以便使用良好的内存管理。
- 确保您导入了您打算在
AppDelegate.h 中使用的所有文件,它应该类似于:#import "FirstView.h
如果您有任何问题,请在评论中告诉我