如何在iphone中以编程方式显示标签栏中的按钮

时间:2011-03-03 13:10:27

标签: iphone

我是iphone开发的新手。在我的应用程序中,我想在标签栏中添加两个按钮。

这里我在视图中显示了barbutton项目,但我不知道如何在标签栏中显示按钮。

任何人都可以帮助我解决我的问题。如何在iphone的programmaticaly中显示标签栏中的按钮。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

查看UITabBar文档: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBar_Class/Reference/Reference.html

您可以使用

- (void)setItems:(NSArray *)items animated:(BOOL)animated

将项目设置为标签栏。 这个项目数组需要包含UITabBarItems,请查看UITabBarItems文档: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITabBarItem_Class/Reference/Reference.html

一个完整的例子是:

UITabBarItem *barItem1 = [UITabBarItem alloc]
                         initWithTabBarSystemItem:UITabBarSystemItemRecents 
                                              tag:10];
[mytabbar setItems:[NSArray arrayWithObjects:barItem1, nil] animated:NO];
[barItem1 release];

我现在刚刚写完这个,所以检查xcode中的代码,它可能会失败。

祝你好运: - )