Re: NSbuttonCell's Bound Title Misbehaving
Re: NSbuttonCell's Bound Title Misbehaving
- Subject: Re: NSbuttonCell's Bound Title Misbehaving
- From: Ian was here <email@hidden>
- Date: Tue, 22 Jul 2008 12:40:32 -0700 (PDT)
Changing the model key path from "value" to "state" in the column's value binding solved the problem.
Thanks.
--- On Tue, 7/22/08, Quincey Morris <email@hidden> wrote:
> From: Quincey Morris <email@hidden>
> Subject: Re: NSbuttonCell's Bound Title Misbehaving
> To: email@hidden
> Date: Tuesday, July 22, 2008, 11:30 AM
> On Jul 22, 2008, at 10:56, Ian was here wrote:
>
> > I have a table with one column. This column uses
> NSButtonCells.
> >
> > I have an array controller whose object class is
> > NSMutableDictionary. It uses two keys:
> "value" and "state". Value is
> > the string that will be used as the title for a button
> cell. State
> > is the state of the button cell, which is a check box.
> The states
> > being checked or unchecked (NSOnState or NSOffState).
> >
> > The table column's value is bound to the array
> controller. The
> > controller key being "arrangedObjects" and
> the model key path being
> > "value".
> >
> > The NSButtonCell (which is attached to the column via
> Interface
> > Builder) has its value bound to the array controller
> as well. The
> > controller key is "selection" and the model
> key path is "state".
> >
> > Finally, I have a table delegate method which is as
> follows...
> >
> >
> > - (void)tableView:(NSTableView *)aTableView
> willDisplayCell:
> > (id)aCell forTableColumn:(NSTableColumn *)aTableColumn
> row:
> > (int)rowIndex
> > {
> > NSArray *arrangedObjects =
> [myArrayController
> > arrangedObjects];
> > NSMutableDictionary *anObject = [arrangedObjects
> > objectAtIndex:rowIndex];
> > NSString *myValueString = [anObject
> > objectForKey:@"value"];
> >
> >
> > [aCell setTitle:myValueString];
> > }
> >
> >
> > Ideally, this would display all of the check boxes in
> the table
> > column, with their respective titles and their current
> state
> > (checked or unchecked).
> >
> > Everything looks perfect when I first run the app. The
> check boxes
> > show their correct state and the titles are correct.
> The problem is
> > when I click on a check box. If I check a box, its
> title changes to
> > "1" and if I uncheck a box, its title
> changes to "0". Has anyone had
> > this problem before?
>
> You're misusing the column binding. It's the
> checkbox's current state,
> not its title. So, when you click on the checkbox, the
> binding updates
> your dictionary's "value" to 0 or 1
> (clobbering the actual title
> string), which you then echo back as the cell's title
> with the last
> line of the delegate method.
>
>
> _______________________________________________
>
> 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
_______________________________________________
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