2

How do I draw "save" & "cancel" buttons on the navigation bar when the user taps "edit"? Also, how do I hide the delete "knobs" and instead make each row editable, like Apple's Contacts app?

Moshe
  • 55,729
  • 73
  • 263
  • 420
Bilal Wahla
  • 645
  • 1
  • 10
  • 27

3 Answers3

3

An UIViewController has a -setEditing:animated: method that you can overwrite. In this method you could call -setRightBarButtonItem or -setLeftBarButtonItem.

As for your second question, take a look at the UITableViewDataSource. There's a method called -tableView:moveRowAtIndexPath:toIndexPath.

EDIT: If you want to enter text in a UITableViewCell, you have to place a UITextField inside it in your -tableView:cellForRowAtIndexPath:. Look here.

Community
  • 1
  • 1
fabian789
  • 7,991
  • 4
  • 39
  • 88
  • Glad I could help. Please use the tick to mark it as the correct answer, so that others can see it too. – fabian789 Dec 12 '10 at 17:41
  • hello! i've posted a new question separately but to keep it in context ive added it here as well. could you please have a look below to see if you could help – Bilal Wahla Dec 12 '10 at 19:36
3

To create a Cancel button on the left side, implement the setEditing:animated: method and put the following inside.

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)] autorelease];

And to add a Save button:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(SaveEdit:)] autorelease];

Make sure you implement cancelEdit: and saveEdit:.

sudo rm -rf
  • 28,958
  • 19
  • 100
  • 160
  • Both answers helped me equally. But I got kind of lost in the other answer. I think this should be the ticked answer. Thanks anyway – Matej Mar 07 '12 at 22:15
1

To both answers, I should add the following:

To remove added button, set the right/leftBarButtonItem to nil

Matej
  • 8,739
  • 7
  • 46
  • 66