iphone - TabBarController + TableViewController + 导航 Controller ?

标签 iphone sdk uinavigationcontroller uitabbarcontroller tableview

我是 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/

相关文章:

visual-studio - 安装Win10 SDK(任何版本)每次都挂

ios - SKProductsRequest 导致崩溃 - Cocos2d 和应用内购买

iPhone:UiNavigationController 后退按钮

iphone - 无法从 XIB 中的属性检查器将 UIWebView 背景颜色更改为 clearcolor

iphone - iOS 开发 : why the scrollView is null

android - 如何从另一个 Activity 中注销 facebook?

iphone - 不符合键值编码

ios - 不在导航栏上制作栏按钮项目和标题(iOS,Swift)

使用 PhoneGap 和 PHP 的 iPhone native 应用程序

ios - 动态获取imageview的位置