Hi Graham and thank you very much for your reply. I think I'm still a bit
confused I do apologize. :-( Here's my code so far so you can see...
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return[filenamescount];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
if([[aTableColumn identifier] isEqualToString:@"column2"])
{
return[NSNumbernumberWithInt:NSOnState];
}
return [filenames objectAtIndex:rowIndex];
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
// This is where I'm stuck!
}
And in this code I am using my variable which is a list of filenames...
NSMutableArray*filenames;
Other than the connections I have in IB I have given this column of checkboxes
the Identifier "column2" in IB. I have not set any other property key like you
mentioned and I'm not sure where I would do that? I'm not using bindings in my
case...I was under the impression it was not necessary? The first 2 methods
seem to work fine and the 3rd method is being called but it's just I couldn't
figure out the code to change the state of the checkboxes...
Thank you again so much for your help,
Rick
________________________________
From: Graham Cox <[email protected]>
To: Jo Phils <[email protected]>
Cc: [email protected]
Sent: Friday, March 20, 2009 1:56:36 PM
Subject: Re: NSTableView updating checkboxes
On 20/03/2009, at 4:43 AM, Jo Phils wrote:
> I am still a Cocoa beginner and looking for some help. Based on Using a
> Table Data Source in the Table View Programming Guide I have initiated my
> Table View with 2 columns...one for filenames and one for checkboxes
> (NSButtonCell). Everything is fine except this method:
>
> - (void)tableView:(NSTableView *)aTableView
> setObjectValue:anObject
> forTableColumn:(NSTableColumn *)aTableColumn
> row:(int)rowIndex
>
> I can't seem to get the right syntax to tell my Table View to toggle the
> state. I am able to initiate my Table View with the checkboxes in the ON
> state (other method) but this method is where I'm stuck. My source is a
> NSArray *filenames and my table column is "column2." If someone could help
> show me how to code this I would appreciate it very much not just to get me
> passed this point but also so I can learn what I'm doing wrong. :-)
You don't actually state clearly what the problem is, but there is a minor
error above:
> setObjectValue:anObject
should be:
> setObjectValue:(id) anObject
is that it?
I believe that types left out default to <id> so it may not be. If your
question is "how do I toggle the state of something in my data model when the
checkbox is changed?" then this may help:
- (void) tableView:(NSTableView*) tv setObjectValue:(id) objectVal
forTableColumn:(NSTableColumn*) column row:(int) rowIndex
{
id someObject;
someObject = [[self dataModel] objectAtIndex:rowIndex];
[someObject setValue:objectVal forKey:[column identifier]];
}
where [column identifier] returns the string which is the property key for the
boolean property of interest that the checkbox is representing. You set this in
IB, e.g. @"myBooleanProperty"
--Graham
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]