Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For those who don't want to override UITableView (e.g. if you're using UITableViewController), here's a simple and clean solution that I use. It basically involves creating your own edit button item and using the tableView's <code>editing</code> flag to track edit vs done. For icing on the cake, it shows a "+" button (instead of "Edit") when the table is empty for adding new items.</p> <pre><code>- (void) updateEditButtonVisibility { // tableItems represents the data structure that s if ([tableItems count] &gt; 0) { UIBarButtonSystemItem editButtonType = self.tableView.editing ? UIBarButtonSystemItemDone : UIBarButtonSystemItemEdit; UIBarButtonItem *editButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:editButtonType target:self action:@selector(editButtonTouched)]; self.navigationItem.rightBarButtonItem = editButtonItem; [editButtonItem release]; } else { UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonTouched)]; self.navigationItem.rightBarButtonItem = addButtonItem; [addButtonItem release]; } } - (void) editButtonTouched { // edit/done button has been touched [self.tableView setEditing:!self.tableView.editing animated:YES]; [self updateEditButtonVisibility]; } - (void) addButtonTouched { // logic to allow user to add new items goes here } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self updateEditButtonVisibility]; } </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