本文介绍了如何在 UINavigation Bar 中添加动态/多按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 UINavigation Bar 中添加动态/多按钮?
How to add dynamic/multi button in UINavigatation Bar?
如下图:
推荐答案
你可以使用一个 UIToolBar 来保存多个 UIBarButtonItem 对象.
You can use a UIToolBar which then hold hold multiple UIBarButtonItem objects.
- (void)viewDidLoad {
[super viewDidLoad];
// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
}
-(void)add{
NSLog(@"Code to add the row in tableview");
}
-(void)refresh {
NSLog(@"code to refresh the tableView");
}
这篇关于如何在 UINavigation Bar 中添加动态/多按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!