• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSButtonCell & tableView (s)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSButtonCell & tableView (s)


  • Subject: NSButtonCell & tableView (s)
  • From: Chad Armstrong <email@hidden>
  • Date: Wed, 22 Jan 2003 23:55:37 -0800

I'm trying to create an app which has an NSTableView with only one column in it. In each row/cell, I want an switch button with a string of words after it. Before I started mucking around with the NSButtonCell and such, I had the app with just strings (instead of NsButtonCells) working just fine. I haven't found much cohesive code to sort out my problems. Here is some of my example code, and I'm hoping someone can identify what is going wrong, or what I need to add. I want to be able to change both the switch box and the string if possible.

- (void) awakeFromNib
{

NSButtonCell *buttonCell = [[[NSButtonCell alloc] init] autorelease];
NSTableColumn *buttonColumn = [table tableColumnWithIdentifier:@"To Do"];

records = [[NSMutableArray alloc] init];

[buttonCell setButtonType:NSSwitchButton];
[buttonCell setImagePosition:NSImageLeft];
[buttonCell setTitle:@""];
[buttonColumn setDataCell:buttonCell];
}



- (id)tableView:(NSTableView*)table objectValueForTableColumn:(NSTableColumn*)col row:(int)rowIndex
{

// return [records objectAtIndex:rowIndex];

id result = nil;
NSDictionary *dict = [records objectAtIndex:rowIndex];

// these didn't agree with the compiler
// id stringValue = [dict objectForKey:[col identifier]];
//id stringValue = [super tableView:inTableView objectValueForTableColumn:inTableColumn row:inRowIndex];

NSString *identifier = [col identifier];



if ([identifier isEqualToString:@"To Do"]) // it doesn't seem to get in here...
{
result = [records objectAtIndex:rowIndex];
//result = [NSNumber numberWithInt:[stringValue intValue]];
// result = @"foo";
NSLog(@"Saw the To Do");
}
else
{
result = [records objectAtIndex:rowIndex];
NSLog(@"NOT in To Do");
}

return result;

}


// really not quite sure how to go about doing this one...
- (void)tableView:(NSTableView*)table
willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn*)col
row:(int)rowIndex
{
// old code before the NSButtonCell was added
// [records replaceObjectAtIndex:rowIndex withObject:aCell];

//NSMutableDictionary *dict = [records objectAtIndex:rowIndex];
//[dict setObject:aCell forKey:[col identifier]];

// [aCell setButtonType: NSSwitchButton];
[aCell setAllowsMixedState:YES];
[aCell setState:NO];
// [aCell setTitle: [itemField stringValue]];
}



Regards,

Chad Armstrong
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSButtonCell & tableView (s)
      • From: Rakesh Pandey <email@hidden>
  • Prev by Date: Re: Thread Safety and Cocoa
  • Next by Date: Re: Subclassing question
  • Previous by thread: Re: Subclassing question
  • Next by thread: Re: NSButtonCell & tableView (s)
  • Index(es):
    • Date
    • Thread