NSArrayController:removeAllObjects不刷新TableView [英] NSArrayController : removeAllObjects does not refresh TableView

查看:106
本文介绍了NSArrayController:removeAllObjects不刷新TableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我直接将对象添加到ArrayController中。当我想要清洁所有物品时,我会做:

In my application I add objects directly to an ArrayController. When I want to clean all items I do:

[[downloadItemsController content] removeAllObjects];

但是该命令不会刷新arraycontroller绑定的TableView。如果删除所有项目并添加其他新项目,我只会看到该项目。很好,但是如果我不添加任何内容,那么表中仍然有我所有的物品。

This command however does not refresh the TableView the arraycontroller is bound to. If I remove all items and add another new items I only see that item. That is fine but if I don't add anything I still have all my items in the table.

如果我这样做

[downloadItemsController prepareContent];

所有旧项目都从表视图中删除,但是我将得到一个新的空项目,我可以对其进行编辑。我不希望这样,因为我的一列中有一个checkboxcell,所以我总是会得到一个带有复选框的行。

all old items are removed from the tableview but than I will get an new and empty item I can edit. I don't want that and because one of my columns has a checkboxcell I always get an row with a checkbox.

我只需要一个没有任何项目的空表删除所有现有项。

I just need an empty table with no items after I remove all existing items.

推荐答案

要从 NSArrayController 对象:

NSRange range = NSMakeRange(0, [[anArrayController arrangedObjects] count]);
[anArrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];

绑定应自动更新。参见原始的SO答案

The bindings should update automatically. See original SO answer.

这篇关于NSArrayController:removeAllObjects不刷新TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆