<分区>
我试图在一个子类 ABPersonViewController 的类中以编程方式创建一个工具栏。 这是我所做的。
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(onToolbarTapped:)];
NSArray *items = [NSArray arrayWithObjects: customItem, nil];
[self.navigationController.toolbar setItems:items animated:NO];
//[self setToolbarItems:[NSArray arrayWithObject:items]];
self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
[self.navigationController setToolbarHidden:NO animated:YES];
工具栏没有出现。我在这里做错了什么。
编辑:我已经按如下方式编辑了我的代码
UIToolbar *toolbar = [[[UIToolbar alloc] init]autorelease];
toolbar.barStyle = UIBarStyleBlackOpaque;
toolbar.tintColor = [UIColor blackColor];
toolbar.frame = CGRectMake(0, 372, self.view.frame.size.width, 45);
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:unblockContact style:UIBarButtonItemStyleBordered target:self action:@selector(onToolbarTapped:)];
customItem.tintColor = [UIColor blackColor];
NSArray *items = [NSArray arrayWithObjects:customItem, nil];
[toolbar setItems:items animated:NO];
[self.view addSubview:toolbar];
[customItem release];
如何让barbuttonitem占据整个工具栏。用户不应该感觉到工具栏上有一个 barbuttonitem。我可以这样做吗,还是有其他方法? 需要帮助。谢谢。