如何在导航栏中添加动态/多按钮?
如下图所示:
答案 0 :(得分:0)
我不赞成iOS5,但在iOS4中你可以做到这一点,只有你自己的导航。酒吧有理由让它定制。
答案 1 :(得分:0)
您可以使用UIToolBar,然后持有多个UIBarButtonItem对象。
- (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");
}