Re: Refreshing of NSTableView with Snow Leopard - solved

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Jan 5, 2010, at 21:58, Trent Jacobs wrote:

> Thanks to Markus and Kyle for your help.
> 
> I have solved the issue but I'm still a bit perplexed...

You shouldn't be, it works as documented.

> 
> Firstly I have to state that I was using the NSArrayController to handle the sorting for me, based on what the user selected. Here was the code I used to set the sorting (I should have included this in my original post):
> 
> 	NSSortDescriptor* sortBySongPosition;
> 	sortBySongPosition = [[NSSortDescriptor alloc] initWithKey:@"songPosition" ascending:YES];
> 	[arrSongSetEntryController setSortDescriptors: [NSArray arrayWithObject: sortBySongPosition]];
> 
> Now as I have stated, this works on all versions prior to Snow Leopard, but with Snow Leopard there was no change in the rendering of the NSTableView. However, when I modified the code to be:
> 
> 	NSSortDescriptor* sortBySongPosition;
> 	sortBySongPosition = [[NSSortDescriptor alloc] initWithKey:@"songPosition" ascending:YES];
> 	// I added this line:
> 	[arrSongSetEntryController setSortDescriptors: nil];
> 	[arrSongSetEntryController setSortDescriptors: [NSArray arrayWithObject: sortBySongPosition]];
> 
> It worked. 
> 
> Hope this helps someone...
> 
> Thanks,
> Trent.
> 

I don't think you can rely on NSArrayController to resort when you use setSortDescriptors:, it's also not documented that way. IIRC this was even true in earlier OS versions. Remember, if you see something that works (in particular situations) that's not documented you should NEVER rely on it, there's absolutely no guarantee it will always work, it may just work as a side effect of the implementation, which may change at any time. Your workaround is also just relying on some implementation detail, and therefore it's no solution. Therefore, when you use setSortDescriptors: you should call -rearrangeObjects. As an aside, this is also more efficient if you want to change several things (like sortDescriptors and filterPredicate), that's perhaps why Apple chose not to resort automatically.

Christiaan

> On 5 Jan 2010, at 14:08, Markus Hitter wrote:
> 
>> 
>> Am 04.01.2010 um 22:54 schrieb Trent Jacobs:
>> 
>>> I'm really confused as to why calling reloadData isn't refreshing the table.
>> 
>> Perhaps, because the table's contents and the controller's arrangedObjects get out of sync this way? Perhaps the table even reloads, just to be re-reloaded by the controller after that. If things go fast, you wouldn't even see a flicker.
>> 
>> As it was already said, getting the NSArrayController to sort those objects the way you want is the way to go.
>> 
>> 
>> Markus
>> 
>> - - - - - - - - - - - - - - - - - - -
>> Dipl. Ing. Markus Hitter
>> http://www.jump-ing.de/
>> 
>> 
>> 
>> 
> 
> _______________________________________________
> MacOSX-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.