开发者

Calling UITableViews delegate methods directly

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

- (void)tableView:(UITableView *)theTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath开发者_如何学JAVA

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜