0

I've tried with following code. It works fine. But I can not figured out how to achieve few things.

screenshot

  1. How to add insertion control when I clicked "Delete" button instead of deletion control on the same row?

  2. If I moved "section 3" in between "Section 1" and "Section 2", how to update all the three sections with deletion control in them?

So far I've got following output using below code.

    -(void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //Handle things when deletion control clicked!

        //[sectionArray removeObjectAtIndex:indexPath.row];
        //[self.tableView reloadData];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        //Handle things when insertion control clicked!
    }
}


    - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // No editing style if not editing or the index path is nil.
    if (isEditMode == NO || !indexPath) return UITableViewCellEditingStyleNone;
    if (indexPath.row == 1){
        return UITableViewCellEditingStyleDelete;
    }else if (indexPath.row == 2){
        return UITableViewCellEditingStyleInsert;
    }else if (indexPath.row == 3){
        return UITableViewCellEditingStyleInsert;
    }else {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}

    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
      toIndexPath:(NSIndexPath *)toIndexPath {
    NSString *item = [sectionArray objectAtIndex:fromIndexPath.row];
    [sectionArray removeObject:item];
    [sectionArray insertObject:item atIndex:toIndexPath.row];

    NSLog(@"%@", sectionArray);
}

2 Answers 2

0

Solution for your second question is that you need to refresh your table view once you performed your action such as deletion and insertion

1
  • Thank you Preejith, I will try it and update it here! I think first I have to figure out how to do the task one.
    – happycoder
    Sep 20, 2013 at 9:38
0

I hope this links also helpful for you.

http://code4app.net/ios/UITableView-actions/50bf05986803fa8e5c000001

http://www.appcoda.com/model-view-controller-delete-table-row-from-uitableview/

For any time of UI problem you also got demo applications from this side.

http://code4app.net

1
  • Thank you Naveen for your reply! I think you did not understand my question or may be Im mistaken. When I clicked on deletion control it will appear delete button at end of the row. Then clicked on that delete button, I want to replace that deletion control with the insertion control, so user can add it to the tableview again! I dont want to delete the row when user clicked on delete button.
    – happycoder
    Sep 20, 2013 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.