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

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

问题描述

我有一个基于导航的应用程序,它显示了一个表格视图,您可以在其中选择一个单元格,它会将您带到该单元格的详细信息视图".我希望这个视图有一个 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

推荐答案

基本上你需要做的就是将一个 Tab View Controller 推送到 Navigation Controller 的 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天全站免登陆