Non-working NSButtonCells (can change state even is not enabled)
Non-working NSButtonCells (can change state even is not enabled)
- Subject: Non-working NSButtonCells (can change state even is not enabled)
- From: "Jean-Olivier Lanctôt-D." <email@hidden>
- Date: Sat, 25 Jan 2003 23:29:25 -0500
Hello list,
I have this weird problem with my NSButtonCells (NSSwitchButtons):
Even if they are NOT enabled, (e.g. GREYED OUT !!) I *can* change their
state (true/false).
it's very very very weird. here's my code.
###CODE
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if(aTableColumn==checkColumn) {
[aCell setState:[[NSNumber numberWithBool:![_unwantedPlugins
containsObject:[_allPlugins objectAtIndex:rowIndex]]] intValue]];
[aCell setEnabled:[[[_allPlugins objectAtIndex:rowIndex]
objectForKey:@"PNPluginIsEssential"] boolValue]];
}else{
NSString *titleText = [NSString stringWithFormat:@"%@
v.%@\n",[[_allPlugins objectAtIndex:rowIndex]
objectForKey:@"PNPluginName"],[[_allPlugins objectAtIndex:rowIndex]
objectForKey:@"PNPluginLatestVersion"]];
NSString *subtitleText = [[_allPlugins objectAtIndex:rowIndex]
objectForKey:@"PNPluginDescription"];
NSColor *titleTextColour;
if(rowIndex == [pluginsTable selectedRow]) {
titleTextColour = [NSColor whiteColor];
}else{
titleTextColour = [NSColor grayColor];
}
NSFont *titleTextFont = [NSFont fontWithName:@"Helvetica-Bold"
size:12.0];
NSFont *subtitleTextFont = [NSFont fontWithName:@"Helvetica"
size:11.0];
NSMutableAttributedString *niceString =
[[[NSMutableAttributedString alloc] initWithString:[titleText
stringByAppendingString:subtitleText]] autorelease];
NSDictionary *titleAttributes = [NSDictionary
dictionaryWithObjectsAndKeys:titleTextFont, NSFontAttributeName,
titleTextColour, NSForegroundColorAttributeName, nil];
NSDictionary *subtitleAttributes = [NSDictionary
dictionaryWithObjectsAndKeys:subtitleTextFont, NSFontAttributeName,
titleTextColour, NSForegroundColorAttributeName, nil];
[niceString setAttributes:titleAttributes
range:NSMakeRange(0,[titleText length])];
[niceString setAttributes:subtitleAttributes
range:NSMakeRange([titleText length],[subtitleText length])];
[aCell setAttributedStringValue:niceString];
[aCell setEnabled:NO];
}
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
if(aTableColumn==checkColumn){
if([_unwantedPlugins containsObject:[_allPlugins
objectAtIndex:rowIndex]]){
[_unwantedPlugins removeObject:[_allPlugins
objectAtIndex:rowIndex]];
}else{
[_unwantedPlugins addObject:[_allPlugins
objectAtIndex:rowIndex]];
}
}
}
- (void)awakeFromNib {
NSButtonCell *switchCell = [[NSButtonCell alloc] init];
[switchCell setButtonType: NSSwitchButton];
[switchCell setImagePosition: NSImageOnly];
[checkColumn setDataCell:switchCell];
[switchCell release];
}
###END-CODE
So, even if I [aCell setEnabled:NO] the cell's state can BE CHANGED!
I don't think this problem is specific to my computer.. I think there's
a problem with my code.. but it seems logical ..
help me,please!
-- Jean-Olivier
_______________________________________________
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.