iPhone:以编程方式将Tab Bar控制器添加到导航控制器 [英] iPhone: Add a Tab Bar controller programmatically to a navigation controller

查看:224
本文介绍了iPhone:以编程方式将Tab Bar控制器添加到导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,我开始使用基于导航的模板。
但是现在我想在底部添加一个Tap Bar控制器,我想在不使用Interface Builder的情况下这样做。谁能告诉我怎么做?
提前致谢!

I'm developing an iPhone application and I started out with the navigation based template. But now i'd like to add a Tap Bar controller at the bottom and I would like to do this without using Interface Builder. Can anybody tell me how to do this? Thanks in advance!

推荐答案

如果您问如何从导航控制器开始,然后允许用户导航到带有tabbar的视图,我在我的iPad应用程序中执行此操作。如果您有兴趣了解我的应用程序如何使用标签栏,请转到我的个人资料中列出的网站。

If you are asking how to start with a navigation controller and then allow the user to navigate to a view with a tabbar, I do exactly this in my iPad app. Go to the website listed in my profile if you are interested to see how my app uses the tab bar.

虽然我使用Interface Builder来完成它。在Interface Builder中,我创建了一种主视图,其中包含底部的tabbar控件和上面的contentUIView。当用户通过视图进行选项卡时,内容视图以编程方式分配给用户感兴趣的视图。

Although, I used Interface Builder to accomplish it. In Interface Builder, I created sort of a master view that contains the tabbar control at the bottom and a "content" UIView above it. As the user tabs through views, the "content" view is programmatically assigned the view that the user is interested in.

我想你也可以在没有IB的情况下完成它。只需使用以下代码:

I suppose you could also accomplish it without IB. Just use code this:

UITabBar *aTabBar = [UITabBar alloc] init];
[[self yourView] addSubview:aTabBar];

当然,您需要创建标签栏项目并为每个项目分配视图控制器。您可能还需要调整标签栏控件的布局参数,使其位于视图的底部。

Of course, you will want to create tab bar items and assign view controllers to each item. You may also have to tweak the tab bar control's layout params so that it sits at the bottom of the view.

这篇关于iPhone:以编程方式将Tab Bar控制器添加到导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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