Question

I was looking for a way to call the edit method directly.

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

I have all my logic for animating manipulated cells, removing from my model array etc. in this method. It is getting called when a user swipes, adds or rearranges, but I would like to call it manually/directly as a background thread changes my model.

I have constructed an NSIndexPath like so:

NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:1];

I just can't figure out how to call something like:

[self.tableview commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:path];

Do I need to gain access to the methods of this plain style UITableView in another way?

Thanks:)

Was it helpful?

Solution

I don't see why you can't call that method, if all you want is for your code to be executed. The docs give a heavy hint that

- (void)setEditing:(BOOL)editing animated:(BOOL)animate

will have the effect of calling that data source method anyhow. It would make better sense to refactor your code from that method into another method and call it both from the data source method and from elsewhere in your code, if that's really what you want to do.

If you really want to just reflect changes in your model, then call [tableView reloadData] - that's what it's for.

OTHER TIPS

I don't know it for sure but maybe if you call the method

- (void)setEditing:(BOOL)editing animated:(BOOL)animate

it could be, that the commitEditingStyle method is called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top