views:

676

answers:

5

So here's what I've got:

  • An NSTableView with an NSMutableArray data source
  • FSEvents monitoring a folder that contains the file that contains the data for the table view (Using SCEvents for Objective-C abstraction goodness)
  • The FSEvents triggers the same function that a reload button in the UI does. This function refreshes the table view with a new data source based on the contents of said file via setDataSource:.

And here's what happens:

  • If I make a change to the file, the FSEvent gets triggered and the refresh method gets called.
  • The array that the table view should be accepting does indeed include the changes that triggered the FSEvent.
  • setDataSource: gets sent to the NSTableView with the correct data source.
  • The changes do not appear in the table view!

But then:

  • If I hit the refresh button, which triggers the exact same method as the FSEvent, the table view gets updated with the new data.

I also tried replacing the FSEvent with an NSNotification (NSApplicationDidBecomeActiveNotification), but the same thing happens.

Anyone have any idea why this is happening?

Edit: For clarification, the jist of my question is this: Why does my NSTableView reload as it should when triggered by a button press, but not when triggered by an FSEvent or an NSNotification?

Edit: Thanks to diciu, I've figured out that in fact all of my UI references point to 0x0 when triggered by the event, but then have valid addresses when triggered by the button click. These objects are all declared in IB, so there's no instantiation or allocation for them going on in my code. So my question is now: what can I do to stop these pointers from pointing to nil?

+1  A: 

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

[myObject performSelector:@selector(reloadAction:) withObject:nil afterDelay:0.0];
Ashley Clark
Yes. That did not work either.
Rich Catalano
+2  A: 

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

This might help, to force the NSTableView to redraw.

I'm not really sure if this is what your asking though. The wording of your question is kind of confusing, you state a series of events, but never a true question.

Brian Gianforcaro
That is what I'm asking. Unfortunately reloadData yields the same results.
Rich Catalano
+1  A: 

You're setting an NSArray directly as the data source of the table view?

That's not how NSTableView works. The data source must be an object that conforms to NSTableDataSource. NSArray doesn't. You write the data source yourself; it will probably be the same object that you currently have calling setDataSource:.

The other way would be to use Bindings.

Peter Hosey
I have a category on NSArray so it conforms to the necessary methods of the `NSTableDataSource` protocol.
Rich Catalano
+1  A: 

Could it be that reference to table view within the scope of your refresh method is not valid?

I.e. are you sure you're not calling [nil reloadData] which does not yield any errors? Your reference to your table view might be nil in the refresh code if you're set it before awakeFromNib or in some other circumstances.

diciu
You're right. All the UI objects are nil when triggered from the event, but have proper addresses when triggered from the button (and awakeFromNib). Interesting…
Rich Catalano
+1  A: 

sounds like when you register for the event/notification, you're passing in a different instance of your controller class.

superfell
This wasn't *exactly* the problem, but I'll mark this one as correct since it pointed me in the right direction.Thanks!
Rich Catalano