2013-02-05 30 views
-2

我已经创建了一个工具栏,如下所示的代码,现在我不知道如何添加项目到它。UIToolbar创建

- (void)viewDidLoad 
{ 
[super viewDidLoad];  
UIToolbar *toolbar = [[UIToolbar alloc] init];  
toolbar.frame = CGRectMake(0, 418, 350, 44); 
NSMutableArray *items = [[NSMutableArray alloc] init]; 
[items addObject:[[[UIBarButtonItem alloc] init] autorelease]]; 
[toolbar setItems:items animated:YES]; 
[items release]; 
[self.view addSubview:toolbar]; 
[toolbar release]; 
} 
+0

你的问题是什么? – ToMfromTO

+0

我无法将按钮添加到工具栏。它在模拟器中显示为空 – reddy

+0

我的问题是如何将按钮添加到此工具栏代码中? – reddy

回答

0

试试这个代码

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item"  style:UIBarButtonItemStyleBordered target:self action:@selector(action:)]; 

NSArray *items = [NSArray arrayWithObjects: customItem, nil]; 
[toolbar setItems:items animated:NO]; 

[customItem release]; 

您也可以参考此链接: How to create this toolbar programmatically

请在发布前做谷歌的搜索和堆栈溢出的搜索。

0

使用 [self setToolbarItems: buttons animated:NO]; 因为你想设置toolbaritems和uiviewcontroller有工具栏本身。