troubleshooting Question

How do I allow a checkbox in NSTableview to be checked and once checked run command

Avatar of Scott_Edge
Scott_Edge asked on
ProgrammingCSwift Programming
3 Comments1 Solution2258 ViewsLast Modified:
Xcode: 3.1.2

I have a NSTableView I am updating from a NSDictionary. The tableview has a checkbox that was added with IB. I can set the checkbox from the NSDictionary but I can't change it's status once it loads. I would like to allow for the status change and then when it does change run an action based of the key of the NSDictionary.

I am very new to Obj-c and am trying to work my way through this. I can track changes with - (void)tableView:(NSTableView *)tableView setObjectValue:(id)aData. what I can't figure out is how to capture the change update the NSDictionary and reload.

Thanks for any help.
- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn
			row:(int)row
{
	NSArray *keysArray = [speakerDict allKeys];
	NSArray *sortedKeysArray =
	[keysArray 
	 sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
	id keyAtRow = [sortedKeysArray objectAtIndex:row];
	
	if ([[tableColumn identifier] isEqualToString:@"speakerNameCell"])
	{
		return keyAtRow;    
	}
 
	return [speakerDict objectForKey:keyAtRow];
} 
 
//HAVING PROBLEM WITH FOLLOWING
 
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)aData 
   forTableColumn:(NSTableColumn *)aCol 
			  row:(int)row
{
//???????	found this code elsewhere
 
id loc_id, loc_data;
 
	
	// identify the table column
	loc_id = [aCol identifier];
//the class comes up ica for my checkbox so this part isn't run
	if ([loc_id isKindOfClass:[NSString class]])
	{
		// determine the old cell value
		loc_data = [[self speakerDict] objectForKey:loc_id];
		loc_data = [loc_data objectAtIndex:row];
		
		// compare the old cell value against the "new" value
		if (![loc_data isEqual:aData])
		{
			// update the data buffer
//the designation for this dictionary is wrong getting warning that foo might not respond to speakerDict
			[[[self speakerDict] objectForKey:loc_id]
			 replaceObjectAtIndex:row withObject:aData];
		}
	}
}
ASKER CERTIFIED SOLUTION
Scott_Edge

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros