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 (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com