How to uncheck checkbox in an NSTableView
How to uncheck checkbox in an NSTableView
- Subject: How to uncheck checkbox in an NSTableView
- From: Lance Kwan <email@hidden>
- Date: Wed, 23 Dec 2009 02:05:07 -0800 (PST)
Good day. I have troubles on unchecking a checkbox in a table view. Here are my codes. Your help is highly appreciated. Im new to cocoa.
declarations
IBOutlet NSTableView* oTableView;
NSMutableArray* oDatas;
NSTableColumn *columnInCheckBox;
-(IBAction)tableViewSelected:(id) sender;
______________________________________________________________________________________
-(id)
init
{
self = [super init];
oDatas = [[NSMutableArray alloc] init];
[oDatas addObject:@"a"];
[oDatas addObject:@"b"];
[oDatas addObject:@"c"];
[oDatas addObject:@"d"];
[oDatas addObject:@"e"];
[oDatas addObject:@"f"];
return self;
}
-(void)awakeFromNib
{
NSButtonCell *dataCell;
dataCell
= [[NSButtonCell alloc] init];
[dataCell setButtonType:NSSwitchButton];
[dataCell setTitle:@""];
columnInCheckBox = [oTableView tableColumnWithIdentifier:@"checkbox"];
[columnInCheckBox setDataCell:dataCell];
[dataCell autorelease];
}
-(IBAction)tableViewSelected:(id) sender
{
int row;
row
= [sender selectedRow];
NSLog(@"row
selected are:%d",row);
}
- (NSInteger)
numberOfRowsInTableView:(NSTableView *)tableView
{
return [oDatas count];
}
- (id)
tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
id returnValue = nil;
if([[tableColumn identifier] isEqualToString:@"data"])
{
returnValue
= [oDatas objectAtIndex:row];
}
else if([[tableColumn identifier] isEqualToString:@"checkbox"])
{
returnValue
= [NSNumber numberWithBool:YES];
}
return returnValue;
}
- (void)
tableView:(NSTableView *)tableView
setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSButtonCell*
buttonCell;
if([[tableColumn identifier] isEqualToString:@"checkbox"])
{
buttonCell =[[tableView tableColumnWithIdentifier:@"checkbox"] dataCellForRow:row];
if([buttonCell state] == 1)
{
NSLog(@"checkbox
is check. Need to uncheck 1");
NSLog(@"current
state %d",[buttonCell state]);
[buttonCell setState:NSOffState];
[buttonCell setNextState];
NSLog(@"new state
%d",[buttonCell state]);
}
else if([buttonCell state]
== 0)
{
NSLog(@"checkbox is uncheck. Need to check");
NSLog(@"current state %d",[buttonCell state]);
[buttonCell setState:NSOnState];
[buttonCell setNextState];
NSLog(@"new state %d",[buttonCell state]);
}
}
}
_______________________________________________
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