Harish
Harish

Reputation: 2512

UITableview Cell adding button in delete method

In my UITableview i have option for user to delete the row, i have done that but here i need to add a EDIT button with the DELETE button like the picture, enter image description here

also when user clicks edit i want to allow the user to edit the ROW TEXT.. is it possible..? Please help.

Upvotes: 0

Views: 436

Answers (3)

Paras Joshi
Paras Joshi

Reputation: 20541

Create Custom cell and add your UIButtons and UITextField and just implement some logic. just refer tutorial from below links.

For Custom cell just see these below links with tutorials and demos:

  1. custom-table-view-cells-in-ipad-programming
  2. creating-custom-table-view-cell
  3. Custom UITableViewCell in IB

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90117

First of all you should ask yourself if you really need that edit button.

The user told you already that he wants to edit the tableView by tapping the edit button of the tableView. In my opinion there is absolutely no need for another edit button, the user will assume that everything he does in edit mode will edit the data.

There are two options:

  1. Put the editing in another view controller that you push when the user taps the cell in edit mode.
    For this you have to set the editingAccessoryType of the cell to UITableViewCellAccessoryDisclosureIndicator, to indicate that the cell can be selected.
    And allowsSelectionDuringEditing of the tableView has to be set to YES.
    Everything else is like handling row selections when not editing. Simply check for [tableView isEditing] in tableView:didSelectRowAtIndexPath:.

  2. Replace the UILabel of your cell with a UITextField with a borderStyle of UITextBorderStyleNone and the same font as the UILabel. Set enabled to NO. This way it will look exactly like a UILabel.
    Implement setEditing:animated: of the UITableViewController to enable each textField in editing mode

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
        for (UITableViewCell *cell in [self.tableView visibleCells]) {
            UITextField *tf = ...
            tf.enabled = editing;
        }
    }
    

    when the user taps the UITextField in edit mode he can input text.


If you really need that edit button add it in - (void)setEditing:(BOOL)editing animated:(BOOL)animated when editing is YES and remove it when editing is NO. Instead of adding and removing it I would just use setHidden:

Upvotes: 1

Rushi
Rushi

Reputation: 4500

Yes it is possible. You'll have to use the UITextField to show the text. When user click on the Edit button you'll have to save the tag of the button. Save this tag so that you know which row is clicked. And then reload the table. While reloading the table make sure you set the userInterActionEnabled property of the UITextField at the particular row to true. It'll allow user to edit the text.

Upvotes: 0

Related Questions