0

I want to delete a row from table view without using the below data source method. How to do it?

- (void) tableView : (UITableView *)tableView 
commitEditingStyle : (UITableViewCellEditingStyle)editingStyle 
 forRowAtIndexPath : (NSIndexPath *)indexPath 
1
  • 1
    Delete the row from the source (NSArray), then reload the tableView. I think this would be work. Commented Aug 9, 2012 at 4:32

3 Answers 3

3

How about [UITableView deleteRowsAtIndexPaths: withRowAnimation:]?

(I've linked Apple's documentation linked for you).

@Scar's idea is also good, but that will refresh the entire table and that might be a bit disruptive to the user if they're scrolled to the bottom of the table and the refresh takes them to the top.

Sign up to request clarification or add additional context in comments.

3 Comments

You have to create it. If you know the row, it's as easy as "NSIndexPath * myIndexPath = [NSIndexPath indexPathForRow: rowNumber inSection: sectionNumber]; (and I've linked this documentation for you, too).
its not fully correct your app will not read the right rows from the backing datasource.
You're right about this, @stackmonster. Not only does the row have to be removed from the table, it has to be removed from the backing data source as well. +1 to you!
3

Not quite that simple, you have to do this atomically with a UITableView

[_tableView beginUpdates]; // <-- pretty important

long selectedRow = _tableView.selectedRow;

[_tableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:selectedRow] withAnimation:NSTableViewAnimationSlideUp];

//then remove your object from the array
[((NSMutableArray*) _searchResults) removeObjectAtIndex:selectedRow];

[_tableView endUpdates];

This prevents delegate methods from being called while the array is being updated.

Comments

1

Remove the row from your model and call -deleteRowsAtIndexPaths:withRowAnimation:.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.