0

I want to add a small button beside my UITableView header that when pressed changes my table view cells to be editable (setting a UITextField in place for the detail label) that I can edit and then I click the button again and it reverts and saves.

Or add a button to the footer that just reads Save and have the cells always editable.

How can I do this?

8vius
  • 5,786
  • 14
  • 74
  • 136

1 Answers1

1

Subclass UITableViewCell, override layoutSubviews to prepare different presentation of normal and editing mode (@property(nonatomic, getter=isEditing) BOOL editing to decide which). Or you can override it's setEditing:animated, but never tried that.

The button then should call something like

[mytable setEditing:YES animated:YES];

When you call this method with the value of editing set to YES, the table view goes into editing mode by calling setEditing:animated: on each visible UITableViewCell object. Calling this method with editing set to NO turns off editing mode. In editing mode, the cells of the table might show an insertion or deletion control on the left side of each cell and a reordering control on the right side, depending on how the cell is configured. (See UITableViewCell Class Reference for details.) The data source of the table view can selectively exclude cells from editing mode by implementing tableView:canEditRowAtIndexPath:.

A-Live
  • 8,904
  • 2
  • 39
  • 74
  • Any user programming guide at hand that explains this in depth? Also any idea on how to do the button deal? – 8vius Mar 16 '12 at 16:09
  • @8vius have a look on the answer here. Not perfectly what you want, but the general idea should be pretty clear: http://stackoverflow.com/questions/742829/animating-custom-drawn-uitableviewcell-when-entering-edit-mode – A-Live Mar 16 '12 at 16:19
  • @8vius what's about the button ? You don't have to call `setEditing:NO` if you don't want to and you can leave the table in the editing mode. In fact, you can show it in the editing mode from the beginning and never switch it off. – A-Live Mar 16 '12 at 17:15
  • Yes, but I meant how can I add a button beside the UITableView header? – 8vius Mar 16 '12 at 17:18
  • @8vius do you mean on the top of the table of on the left/rite side ? The former is easy with table's `tableHeaderView` property, and the later is more complicated as sections headers are changing the width automatically to match the table width, the solution is to use `viewForHeaderInSection`, create your own header view and add the button out of the header frame as a subview. Table's `clipSubviews` must be `NO` to make the subview visible out of the table frame. Or you can play with header's `UIViewAutoresizing`. – A-Live Mar 16 '12 at 22:16