NSCollectionView Repainting Issue – Solved
Our new Mentat client for OS X makes extensive use of NSCollectionView, and it has, for the most part worked pretty well for us. The only major issue we've had is that our Mentat event handler code has never been able to actually get the NSCollectionView to update itself.
If someone assigns a task to me, I'll get it via the event listener, and the application will create a new task and insert it at the top of my Agenda. All of this happens except the part where the new task gets drawn - the view acted like nothing had changed.
It turns out that the KVO events that NSCollectionView uses to update itself really don't work very well unless they happen in the main application thread. Once I found out about this it was fairly simple work to rewrite our event handlers to call performSelectorOnMainThread and execute our response code on the main application thread instead of in our network listener's thread.
Once this was in place, everything worked like a charm. After the days I've spent poring over my code, I felt kind of like Chevy Chase in Christmas Vacation once things were set up correctly.
In retrospect, this was really not much of a surprise. Code for the BlackBerry won't even compile if you try to call blocking APIs from the network thread for very similar reasons.
So that's handled and progress is underway once again. Bye for now.
-Daniel
Technorati Tags:
apple, GUI, Mentat, os x, user interface design, NSCollectionView, Threads