I am currently working through Cocoa Programming for OS X and have reached to the end of Chapter 10 where you work with the User Defaults and set a custom background color for a table view with a pref panel.
So far I have been unable to get that to work! I always get the default background colors. I've checked the API reference and everything is still intact etc.
I have used NSLog to output the values in the MyDocument.m file and it looks like its being set, but I'm not seeing the results in the window.
Here is the code from the -windowControllerDidLoadNib method:
- (void)windowControllerDidLoadNib
NSWindowController *) aController
{
NSData *colorAsData;
[super windowControllerDidLoadNib:aController];
colorAsData = [[NSUserDefaults standardUserDefaults]
objectForKey:BNRTableBgColorKey];
NSLog(@"Current Table Color:%@ : New Table Color Will Be: %@",[tableView backgroundColor],[NSKeyedUnarchiver unarchiveObjectWithData:colorAsData]);
[tableView setBackgroundColor:[NSKeyedUnarchiver
unarchiveObjectWithData:colorAsData]];
NSLog(@"New Table Color:%@",[tableView backgroundColor]);
}
And here is the log output:
2007-12-16 00:28:45.248 RaiseMan[7922:10b] Current Table Color:NSNamedColorSpace System controlBackgroundColor : New Table Color Will Be: NSCalibratedRGBColorSpace 1 0.765541 0.607648 1
2007-12-16 00:28:45.249 RaiseMan[7922:10b] New Table Color:NSCalibratedRGBColorSpace 1 0.765541 0.607648 1
What am I doing wrong???
So far I have been unable to get that to work! I always get the default background colors. I've checked the API reference and everything is still intact etc.
I have used NSLog to output the values in the MyDocument.m file and it looks like its being set, but I'm not seeing the results in the window.
Here is the code from the -windowControllerDidLoadNib method:
- (void)windowControllerDidLoadNib
{
NSData *colorAsData;
[super windowControllerDidLoadNib:aController];
colorAsData = [[NSUserDefaults standardUserDefaults]
objectForKey:BNRTableBgColorKey];
NSLog(@"Current Table Color:%@ : New Table Color Will Be: %@",[tableView backgroundColor],[NSKeyedUnarchiver unarchiveObjectWithData:colorAsData]);
[tableView setBackgroundColor:[NSKeyedUnarchiver
unarchiveObjectWithData:colorAsData]];
NSLog(@"New Table Color:%@",[tableView backgroundColor]);
}
And here is the log output:
2007-12-16 00:28:45.248 RaiseMan[7922:10b] Current Table Color:NSNamedColorSpace System controlBackgroundColor : New Table Color Will Be: NSCalibratedRGBColorSpace 1 0.765541 0.607648 1
2007-12-16 00:28:45.249 RaiseMan[7922:10b] New Table Color:NSCalibratedRGBColorSpace 1 0.765541 0.607648 1
What am I doing wrong???