任何“非 TabBar 模板”基于如何添加 UITabBar 的教程?
我想将 TabBar 添加到我已经启动的现有基于视图的应用程序中,只是为了允许用户切换到应用程序的其他部分,例如“关于”部分和另一个名为“已保存的搜索”的部分来显示导航内容(已保存的搜索列表 > 具体搜索结果 > 产品详细信息)。
关于如何做到这一点有什么想法吗?我找到的所有教程都直接将我指向 TabBar 模板。
感谢您的帮助,
斯蒂芬
I would like to add a TabBar to an existing view-based application I already started just to allow the user to switch to other parts of the app like the "About" section and another section entitled "Saved Searches" to display a navigational content (saved searches list > specific search result > product details).
Any idea on how to do this ? All tutorials I found point me directly to a TabBar template.
Thx for helping,
Stephane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从 UITabBar 应用程序模板开始,您会发现这非常容易做到:
在您的
UIApplicationDelegate
类中,在实例化UITabBarController
方法中,如下所示:
然后您设置将出现在选项卡栏上的视图控制器:
这是一个您之前可以使用
UIViewController
子类创建的NSArray
:在此之后,您只需将其设置为窗口的根视图控制器,或将其添加为子视图(它具有相同的效果,但第一种方法在 iOS 4 之前不起作用)
或
然后
要实现您在问题中所说的导航类型,视图控制器你设置的 tabBar 应该是
UINavigationController
的实例,它们很容易像这样创建:在它们内部,你可以推送(导航到)其他视图控制器做:
希望对它的简短回顾使有点清楚了:)
You could start off with the UITabBar Application Template and you'll realize it's very easy to do:
In your
UIApplicationDelegate
class, in the methodInstantiate a
UITabBarController
like this:Then you set the view Controllers that will appear on the tab bar:
Which is a
NSArray
you can previously create with yourUIViewController
subclasses:After this, you only have to set it as the root view controller of the window, or add it as a subview (it has the same effect, but the first approach doesnt work prior to iOS 4)
or
And then
To achieve the kind of navigation that you say in your question, the view controllers you set to the tabBar should be instances of
UINavigationController
, which are very easy to create like this:And inside them, you can push (navigate to) other view controllers doing:
Hope this brief review of it makes it a bit clear :)
您可以创建一个新的
UITabBarController
,并将其视图添加为应用程序窗口的子视图。然后,将其他视图控制器(针对“关于”和“保存的搜索”部分)添加到该选项卡栏控制器。这可以在 Interface Builder 中最轻松地完成。在
MainWindow.xib
中,将选项卡栏控制器对象拖到画布上。这将自动创建一个包含两个项目的选项卡栏(每个添加的视图控制器一个)。对于选项卡栏控制器下的每个视图控制器,转到身份检查器并将其类更改为自定义视图控制器子类。然后,显示属性检查器,并有一个“NIB 名称”字段 - 再次将其设置为适当的笔尖名称。然后将从相应的 nib 文件加载您的自定义控制器视图。剩下要做的就是在 Interface Builder 中命名每个选项卡,并给它一个图形。如果您不喜欢 IB,您也可以通过编程方式执行此操作,方法是将自定义视图控制器分配给选项卡控制器的
viewControllers
属性,并分配selectedViewController
。希望这有帮助。
编辑
认为显示一点层次结构可能会有所帮助!您的
MainWindox.xib
结构可能如下所示:并照常从 SavedSearchesViewController 推送适当的视图控制器以提供导航内容。
You can create a new
UITabBarController
, and add it's view as a subview of your applications window. Then, add your other view controllers (for your "About" and "Saved Searches" sections) to that tab bar controller.This can be done most easily in Interface Builder. In your
MainWindow.xib
, drag a Tab Bar Controller object onto the canvas. This will automatically create a tab bar with two items (one for each of the view controllers added). For each view controller under the tab bar controller, go to the identity inspector and change its class to your custom view controller subclass. Then, show the attributes inspector and there is a field "NIB Name" - again, set this to the appropriate nib name. Your custom controller views will then be loaded from their corresponding nib files. All that's left to do is name each tab in Interface Builder, and give it a graphic.You can also do this programmatically if you don't like IB, by assigning the custom view controllers to the tab controller's
viewControllers
property, and assign aselectedViewController
.Hope this helps.
EDIT
Thought it might be helpful to show a little hierarchy! Your
MainWindox.xib
structure might look something like this:And push appropriate view controllers from SavedSearchesViewController as normal to provide navigation content.