Problem with bindings and Shared User Defaults
Problem with bindings and Shared User Defaults
- Subject: Problem with bindings and Shared User Defaults
- From: Michael Fey <email@hidden>
- Date: Sun, 5 Aug 2007 20:34:45 -0400
Folks,
I have a small issue with bindings and Shared User Defaults. Here's
the quick breakdown with a long-winded explanation after that:
I am using Shared User Defaults to save which columns in a table a
user has chosen to display. The user can use either a right-click
menu or a panel full of check boxes to decide which columns are
shown. Both the menu items and check boxes are connected through
Shared User Defaults. I have used the [NSUserDefaults
standardUserDefaults] to dictate that the first two columns should be
shown when the app is first launched. The first time the app is
launched the first two columns are shown, the check boxes in the
panel are checked, but the menu items that correspond are not.
Here's the extra details:
In Interface Builder all of these columns are displayed in the
table and bound to a value in my data model. The menu is added to
the table header like so:
[[tableView headerView] setMenu:tableColumnSelectionMenu];
In conjunction with this menu I've implemented an NSPanel containing
a set of check boxes that also allows the user to select which
columns are displayed. Each check box corresponds to an item in the
menu with both the menu and the check box's value being bound to a
key in the Shared User Defaults.
To ensure that there are some columns shown the first time a user
starts my app I define some standard user defaults from the
Controller's init method:
- (void)defineStandardUserDefaults
{
NSUserDefaults* standardDefaults = [NSUserDefaults
standardUserDefaults];
[standardDefaults registerDefaults:[NSDictionary
dictionaryWithObjectsAndKeys:
@"YES", @"showColumnOne",
@"YES", @"showColumnTwo",
nil]];
}
Within my Controller's awakeFromNib method I then check to see if
each column should be displayed in the table or not:
if (![defaults boolForKey:@"showColumnOne"])
[tableView removeTableColumn:tableColumnOne];
The first time a user starts up the app it shows columns one and
two. However, if the user right-clicks on the column header none of
the column-toggle menu items are checked. Yet, if the user chooses
to display the NSPanel that also controls the columns, the first two
check boxes are checked as expected. If the user uses the right-
click menu and selects the first two items, duplicates of the first
two columns are added to the table view. If the app is then quit and
relaunched, everything works as it should and the checked menu items
correspond to the checked check boxes.
Has anyone run into this one before?
Regards,
Michael Fey
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden