views:

122

answers:

2

Hi

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:)

A: 

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.

schaechtele
Thanks both of You, I can see that my question could be read as if I am using the standard approach, sorry for that:)
RickiG
+1  A: 

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.

Paul Lynch
Hi PaullI have build a custom set of cells that uses its own set of editing graphics. So I already know the user wishes to delete these cells. If I set editing to YES, it will present the framework controls for doing such, this is not my goal here.I agree that calling commitEditingStyle directly should be straight forward but doing this: [self.tableView:self.tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:path];Results in an "unrecognized selector" message, even though autocompletion is Xcode was happy to offer it to me as a method on the tableView?
RickiG
The method name is correct - but it isn't implemented by a tableView; it is a method that a data source has to implement, to reflect the changes you have made to the table in your model.
Paul Lynch
I see. So instead I should change my model to reflect the current state of things then update through the correct channels. When I did tableview.dataSource = self, I implemented the method. I probably will have to implement beginUpdates and endUpdates instead of trying to force the TableView to do animations when it thinks no changes have been made yet.Thank you, I promise to stop fighting the framework:)
RickiG