Updating UI Date formats on user NSUserDefault changes
Updating UI Date formats on user NSUserDefault changes
- Subject: Updating UI Date formats on user NSUserDefault changes
- From: Danny Frey <email@hidden>
- Date: Sat, 25 Sep 2004 14:26:53 +0100
Hi
I'm displaying a date in an NSTableView column, I took a look at
Mail.app to see how to do it right.
Mail date fields update themselves immediately if a change is made in
the System Preferences, International settings, Dates Formats.
Specifically clicking on the Customize button and then changing the
Long Date popups, then clicking OK makes the change.
I'd like this kind of behaviour in my app, does anyone have a clue as
to the right way to go about this?
My thanks in anticipation,
Danny
------------------------------------------------------------------------
------------------
Where I've been so far....
First stop was registering for the appropriate notification as below:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChangeNotification:)
name:@"NSUserDefaultsDidChangeNotification" object:nil];
As noted elsewhere in this list I do get calls from all manner of other
objects changing (window size etc.) but unfortunately I don't get a
notification when those dates are altered.
Next stop was to follow mmalc's earlier postings on binding to the
NSUserDefaults.
I added myself as an observer to watch the user defaults format string
changing as shown:
[[NSUserDefaultsController sharedUserDefaultsController]
addObserver:self forKeyPath:[NSString stringWithFormat:@"values.%@",
NSDateFormatString] options:0 context: NULL];
I implemented the following method in "self" but it isn't called on
changing the date defaults.
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object
change:(NSDictionary *)change context:(void *)context
Digging deeper I took a look in the user defaults dictionary, date
format string is set to: "%c" so I can see why the above isn't working.
ie.
359 : <CFString 0xa09f3050 [0xa01900e0]>{contents =
"NSDateFormatString"} = <CFString 0x572080 [0xa01900e0]>{contents =
"%c"}
Comparing the user defaults dictionary before and after a change to the
dates revealed that the following dictionary contents was all that was
changed:
186 : <CFString 0x593770 [0xa01900e0]>{contents =
"AppleICUDateFormatStrings"} = <CFDictionary 0x5937a0
[0xa01900e0]>{type = mutable, count = 4, capacity = 17, pairs = (
1 : <CFString 0x594ec0 [0xa01900e0]>{contents = "2"} = <CFString
0x58efa0 [0xa01900e0]>{contents = "d' 'MMM', 'yyyy"}
4 : <CFString 0x594ed0 [0xa01900e0]>{contents = "3"} = <CFString
0x58e940 [0xa01900e0]>{contents = "d' 'MMMM', 'yyyy"}
7 : <CFString 0x593890 [0xa01900e0]>{contents = "4"} = <CFString
0x5938a0 [0xa01900e0]>{contents = "EEEE', 'd' 'MMMM', 'yyyy"}
21 : <CFString 0x58dbb0 [0xa01900e0]>{contents = "1"} = <CFString
0x58e000 [0xa01900e0]>{contents = "yy'/'M'/'d"}
)}
Now observing the dictionary doesn't work as it stays the same so how
should I proceed?
All seems a bit complicated, which is why Im posting I guess :-)
All the best
Danny
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden