我是 iPhone 开发新手,我想制作一个结合 TabBarController + UITableViewController
+ UINavigationController
的应用程序。我知道这个问题在一些视频教程和线程中得到了广泛讨论,但其中一些是针对旧的 xcode 和 sdk 版本的,我在学习教程时遇到了问题。
如果有人可以帮助我提供最新的教程或源文件,我将很高兴。
要明确的是,我试图让我的应用程序基于带有两个选项卡的选项卡栏 Controller :第二个将是一个简单的 View ,第一个应该包含一个 tableviewcontroller 和一个导航 Controller 。当我单击某个单元格时,它应该移动到另一个“详细信息” View 。
任何帮助都会很棒。
最佳答案
好吧,这会很长:
在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];
对两个 View 都执行此操作
然后,如果您想设置任一 View 的标题(这将是选项卡栏中显示的标题),请按以下步骤操作:
firstViewController.title = @"Welcome";
然后为其中包含 UITableView
的 View 创建 UINavigationController
,如下所示:
navController = [[UINavigationController alloc] init];
[navController pushViewController:firstViewController animated:NO];
现在您有了一个 UIViewController
和一个 UINavigationController
,其中包含一个 UIViewController
。
剩下的就是将两个选项卡放入 UITabBarController
中:
mainTabBar.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];
然后只需将标签栏 Controller 放在屏幕上即可:
[window addSubview:mainTabBar.view];
需要记住的几件事:
- 确保释放所有调用 alloc 的内容,以便使用良好的内存管理。
- 确保导入要在
AppDelegate.h
中使用的所有文件,它应类似于:#import "FirstView.h
如果您有任何疑问,请在评论中告诉我
关于iphone - TabBarController + TableViewController + 导航 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196665/