使用TabBar的基于导航的应用程序 [英] Navigation Based Application with TabBar

查看:135
本文介绍了使用TabBar的基于导航的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于导航的应用程序,它显示了一个TableView,您可以在其中选择一个单元格,它会带您进入该单元格的详细信息视图。我希望这个视图有一个TabBar,我可以在3个子视图之间进行选择。我在网上找到了几个解决方案,但没有一个非常有帮助。是否有专门的教程或是他们的源代码,说明如何做到这一点?谢谢

I have a Navigation-Based Application that shows a TableView where you can select a cell and it brings you to a "Detail View" for that cell. I want this view to then have a TabBar where I can select between 3 subviews. I have found several solutions online for this but none are very helpful. Is there a tutorial for this specifically or is their source code indicating how it can be done? Thanks

推荐答案

基本上你需要做的是将标签视图控制器推到导航控制器的viewcontroller堆栈上。

Basically What you need to do is push a Tab View Controller onto the Navigation Controller's viewcontroller stack.

从全新的基于导航的应用程序模板开始。我在RootViewController.m中添加了以下方法:

Starting with a fresh "Navigation-Based Application" template. I added the following method in RootViewController.m :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Navigation logic may go here. Create and push another view controller.
UIViewController *viewOneViewController =   [[UIViewController alloc] init];
viewOneViewController.title = @"One";
viewOneViewController.view.backgroundColor = [UIColor redColor];

UIViewController *viewTwoViewController =   [[UIViewController alloc] init];
viewTwoViewController.title = @"Two";
viewTwoViewController.view.backgroundColor = [UIColor orangeColor];

UIViewController *viewThreeViewController = [[UIViewController alloc] init];
viewThreeViewController.title = @"Three";
viewThreeViewController.view.backgroundColor = [UIColor greenColor];

UITabBarController *anotherViewController = [[UITabBarController alloc] init];
anotherViewController.viewControllers = [NSArray arrayWithObjects:viewOneViewController, viewTwoViewController, viewThreeViewController, nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];

}

将此更改为25到测试:

Changed this to 25 to test:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 25;
}

现在,当我构建并运行时,我会看到你在寻找什么一个基本的方式。完成此工作后,您将要执行的操作是将UIViewControllers更改为您创建的自定义子类,以保存每个视图的代码。 (如果您还在使用Interface Builder,请将init更改为initWithNibNamed:)。

Now when I build and run I'll see what you are looking for in a basic way. What you will want to do after you get this working is to change the UIViewControllers to Custom Subclasses that you create to hold the code for each view. (If you are also using Interface Builder, change the init to initWithNibNamed:).

希望这可以帮助您顺利完成任务。

Hope this helps you get on your way a bit.

这篇关于使用TabBar的基于导航的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆