Re: Checkboxes in Table Views
Re: Checkboxes in Table Views
- Subject: Re: Checkboxes in Table Views
- From: James Housley <email@hidden>
- Date: Tue, 3 Jan 2006 22:13:58 -0500
On Jan 3, 2006, at 9:01 PM, Steve Woodward wrote:
I searched the archives and found a few relevant threads, but I'm
still lost....
I have a window with a table view that contains checkboxes in a
column. I can get the checkboxes to display, but I'm at a loss as
to how to set/get the checkboxes in relation to the data source (in
my case, it's a postgresql database that I connect to with my own
framework). I've worked through some of the code snippets found in
my search but all were incomplete. Apple's documentation wasn't
much help either.
So I'm just looking for pointers in the right direction, or code
snippets, that pertain to using checkboxes in tableviews with an
external data source.
Many TIA.
Here is what I did.
Like you I set the column to be checkboxes in Interface Builder.
Then in the code I customized the checkbox with the following code.
NSButtonCell *prototypeCell = [[[NSButtonCell alloc]
initTextCell:@""] autorelease];
[prototypeCell setEditable: YES];
[prototypeCell setButtonType:NSSwitchButton];
[prototypeCell setImagePosition:NSImageOnly];
[prototypeCell setControlSize:NSSmallControlSize];
[prototypeCell setTarget:self];
[prototypeCell setAction:@selector(uploadFileCheckBox:)];
[[enclosureTable tableColumnWithIdentifier:@"UploadCheckBox"]
setDataCell:prototypeCell];
Then I have this module
- (void)uploadFileCheckBox:(id)sender
{
int oldValue = ![[[itemsWithEnclosuresCheckbox objectAtIndex:
[enclosureTable selectedRow]] objectAtIndex:0] intValue];
[[itemsWithEnclosuresCheckbox objectAtIndex:[enclosureTable
selectedRow]] replaceObjectAtIndex:0 withObject:[NSNumber
numberWithInt:oldValue]];
}
And in my tableView delegate I have
- (id)tableView:(NSTableView *)aTable objectValueForTableColumn:
(NSTableColumn *)aTableColumn row:(int)rowIndex
{
NSString *identifier = [aTableColumn identifier];
if ([identifier isEqualToString:@"UploadCheckBox"])
{
return [[itemsWithEnclosuresCheckbox objectAtIndex:rowIndex]
objectAtIndex:0];
}
}
This I was I figured out and works (the best part) for other peoples
code and messages I found. This might not be the very best, but it
does work for me.
Jim
--
/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden http://www.FreeBSD.org The Power to Serve
email@hidden http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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