NSTableView -setDataSource not working when FSEvents fires

So, here's what I have:

  • NSTableView with NSMutableArray data source
  • FSEvents keeps track of the folder containing the file containing the data for the table view (using SCEvents for the Objective-C abstraction)
  • FSEvents fires the same function as the reload button in the user interface. This function updates the table view with a new data source based on the contents of the specified file via setDataSource:

    .

And here's what happens:

  • If I make changes to the file, the FSEvent is triggered and the update method is called.
  • The array that should receive the table receive does indeed include the changes that caused the FSEvent.
  • setDataSource:

    is sent to the NSTableView with the correct data source.
  • Changes are not reflected in the table view!

But then:

  • If I click the refresh button, which runs the same method as the FSEvent, the table view is refreshed with new data.

I also tried replacing FSEvent with NSNotification ( NSApplicationDidBecomeActiveNotification

), but the same thing happens.

Does anyone know why this is happening?

Edit: For clarification, the gist of my question is, why does my NSTableView reload like it should when a button is clicked, but not when an FSEvent or NSNotification fires?

Edit: Thanks to diciu , I realized that actually all my links in the UI point to 0x0 when the event is fired, but then have valid addresses when the button is pressed. These objects are all declared in IB, so there is no instance or allocation for them in my code. So now my question is, what can I do to keep these pointers from pointing to zero?

0


source to share


5 answers


sounds like when you register for an event / notification you are passing another instance of your controller class.



+1


source


We call reloadData on the NSTableView when we have new data to add / remove to the table.

It might help to force the NSTableView to redraw.



I'm not sure if this is what you are asking about. The wording of your question is somewhat confusing, you are claiming a series of events, but you are never the true question.

+2


source


Have you tried calling your method from your FSEvent on the second pass of your run loop?

[myObject performSelector:@selector(reloadAction:) withObject:nil afterDelay:0.0];

      

+1


source


Are you setting NSArray

directly as a table data source?

This is not how it works NSTableView

. The data source must be an object that matches NSTableDataSource

. NSArray

not. You write the data source yourself; it will probably be the same object you are currently calling setDataSource:

.

Another way is to use Bindings.

+1


source


Maybe the reference to the table view within the scope of your update method is not valid?

those. are you sure you are not calling [nil reloadData] which gives no errors? Your table view reference may be null in the update code if you configured it before awakeFromNib or in some other circumstance.

+1


source







All Articles