Add 2 UIButtons to a UINavigationBar right item


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // create a toolbar to have two buttons in the right
  2. UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 90.0, 44.01)];
  3.  
  4. // create the array to hold the buttons, which then gets added to the toolbar
  5. NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
  6.  
  7. // create a standard "add" button
  8. UIButton *btnAdd = [[UIBarButtonItem alloc]
  9. initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
  10. [buttons addObject:btnAdd];
  11. [btnAdd release];
  12.  
  13. // create a "edit" button
  14. UIButton *btn = [[UIBarButtonItem alloc]
  15. initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(edit)];
  16. [buttons addObject:btnEdit];
  17. [btnEdit release];
  18.  
  19. // stick the buttons in the toolbar
  20. [tools setItems:buttons animated:NO];
  21. [buttons release];
  22.  
  23. // and put the toolbar in the nav bar
  24. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
  25. [tools release];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.