views:

646

answers:

6

Hi everyone!

I'm looking for a way to delete all rows of an NSTableView.

The table view has a data source but it isn't set as a variable so if I need a data source, I have to have something like "data source of tableView" to access it.

Thanks in advance.

+1  A: 

Erm, you can't actively 'delete' cells, you can only passively stop providing them.

refulgentis
+1  A: 

You want to either remove all items from the data source or supply a different data source. You can also hint to the NSTableView that it should refresh after you make such a change.

Quinn Taylor
I use this in AppleScript Studio:set contents of TableView to {}I didn't find any documentation on deleting rows in either NSTableView or NSTableViewDataSource. Maybe @refulgentis is right.
JamesGreen
+1  A: 

Remove all of the items from the datasource or change the datasource.

Then call reloadData

Jacob Relkin
A: 

When you say "if I need a datasource" it makes it sound like you have a misunderstanding about how table views work. You do understand that you write the datasource, right? It isn't a part of the tableview, it's the part of your code that the tableview asks questions of. Tableviews don't hold data. They just ask you (the datasource) how many rows there are, and then what goes in each row and column.

You probably want to work through the Table Views Programming Guide, which will cover all of these issues in detail.

Rob Napier
I have a data source but it's from AppleScript Studio, I can't access it from ObjC.
JamesGreen
This is not what is meant by a "data source." I don't mean just where you get your data from, but an object that implements the correct protocol so the tableview can request data as it needs it. It is a required part of using NSTableView; it may or may not actually hold the data itself. Please read the above doc; it goes into all of these issues with examples.
Rob Napier
A: 

Perhaps an alternative solution to your problem is to use an array controller and bind your table columns to the array controller. Your array controller could control an array of dictionaries, each key in the dictionary representing a column in the table view.

If you have a setup like this, then to clear the table view, you simply empty the array that the array controller is controlling.

dreamlax
A: 

@Rob Napier, The data source from AppleScript Studio is indeed an object, it stores my information, I just can't access it because it's written in another language but after all it's the same object. It's not the place where I get the data rows but where they're stored.