Note that there are some explanatory texts on larger screens.

plurals
  1. POuitoolbar in navigation bar.
    text
    copied!<p>this is a simple problem, but i'm new to xcode dev. I followed a guide online to have multiple buttons on a navigation bar. the edit button on the navgivation bar has a <code>IBAction</code> method called "editButton". which has a <code>(id)sender</code> as parameter. do I get the sender and change the text from edit to done, done to edit? </p> <p><code>"UIBarButtonitem *bbi = (UIBarButonItem *) sender;"</code> doesn't seem to be working. how do i get the button in the toolbar in navigationbar?</p> <p>Thank you.</p> <pre><code>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:3]; // create a standard "add" button UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL]; bi.style = UIBarButtonItemStyleBordered; [buttons addObject:bi]; [bi release]; // create a spacer bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; [buttons addObject:bi]; [bi release]; // create a standard "EDIT" button bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButton:)]; 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]; -(IBAction)editButton:(id) sender{ UIBarButtonitem *bbi = (UIBarButonItem *) sender; if (bbi title isequalsString:@"Done){ [bbi setTitle:@"Edit"]; } }else{ [bbi setTitle:@"Done"]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload