设置UINavigationController的工具栏项 [英] Setting Toolbar Items of UINavigationController

查看:201
本文介绍了设置UINavigationController的工具栏项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone OS 3.0中,您可以使用 setToolbarItems:animated:方法设置UINavigationController的工具栏项目。然而,这需要你传递一个UIToolbarItems数组。虽然我可以通过编程方式创建这些工具栏项,但我宁愿在Interface Builder中创建它们。

In iPhone OS 3.0, you can set the toolbar items of a UINavigationController using the setToolbarItems:animated: method. However, this requires you pass in an array of UIToolbarItems. While I could programmatically create these toolbar items, I'd rather create them in Interface Builder if possible.

为此,我在MyGreatViewController中创建了一个UIToolbar。 xib并且已经用想要的工具栏项目填充它。然后,在MyGreatViewController.m中,我从工具栏中获取项目,并将它们传递给 setToolbarItems:animated:

With this in mind, I have created a UIToolbar in "MyGreatViewController.xib" and have populated it with the wanted toolbar items. Then, in "MyGreatViewController.m", I get the items from the toolbar and pass them to setToolbarItems:animated::

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setToolbarItems: [toolbar items]];
}

...其中工具栏是一个指向UIToolbar的IBOutlet。

...where toolbar is an IBOutlet referring to the UIToolbar.

这是一个好方法吗?有没有更好的方法来完成这个?我应该以编程方式创建项目吗?

Is this a good approach? Is there a better way to accomplish this? Should I just create the items programmatically?

推荐答案

这是一个完全可以接受的方式,但请记住加载xib文件在iPhone上相当昂贵,在viewDidLoad方法中可以更快地创建工具栏项目。

It's a perfectly acceptable way of doing it, but do bear in mind that loading xib files is quite expensive on the iPhone, and it may well be faster to create the toolbar items programatically in your viewDidLoad method.

这篇关于设置UINavigationController的工具栏项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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