直接调用 UITableViews 委托方法

发布于 2024-08-29 01:08:26 字数 626 浏览 1 评论 0原文

我正在寻找一种直接调用编辑方法的方法。

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

我拥有用于​​动画操作单元的所有逻辑,从我的模型数组中删除 等等在这个方法中。当用户滑动、添加或重新排列时会调用它,但我想调用 它手动/直接作为后台线程更改我的模型。

我已经构建了一个像这样的 NSIndexPath :

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

我只是不知道如何调用类似的东西:

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

我是否需要以另一种方式访问​​这个普通样式 UITableView 的方法?

谢谢:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烦人精 2024-09-05 01:08:26

如果您只想执行代码,我不明白为什么您不能调用该方法。该文档给出了一个重要的提示,

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

无论如何都会产生调用该数据源方法的效果。如果您确实想要这样做,那么将您的代码从该方法重构为另一个方法并从数据源方法和代码中的其他位置调用它会更有意义。

如果您确实只想反映模型中的更改,请调用 [tableView reloadData] - 这就是它的用途。

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.

始于初秋 2024-09-05 01:08:26

我不确定,但也许如果您调用该方法

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

,则可能会调用 commitEditingStyle 方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文