Breaking News
Home / iOS / iOS Snippets / How to add a button to a navigation toolbar in iOS?

How to add a button to a navigation toolbar in iOS?

Answer

There can be 2 buttons added to the UINavigationItem using the following approach one to the right named as “Send” and other to the left named as “Cancel”

  1.  UIBarButtonItem *sendButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Send", @"")       style:UIBarButtonItemStyleBordered  target:self action:@selector(sendMessage:)] autorelease];
  2.    
  3.     self.navigationItem.rightBarButtonItem = sendButton;
  4.    
  5.     UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel", @"")       style:UIBarButtonItemStyleBordered  target:self action:@selector(cancelMessageSend:)] autorelease];
  6.  
  7.    
  8.     self.navigationItem.leftBarButtonItem = cancelButton;
[pb_builder]

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger