Cell in Selected NSTableView Not Redrawn
Cell in Selected NSTableView Not Redrawn
- Subject: Cell in Selected NSTableView Not Redrawn
- From: Keary Suska <email@hidden>
- Date: Fri, 20 Jul 2012 20:03:54 -0600
In an NSTableView I am providing custom cells via tableView:dataCellForTableColumn:row:, based on values represented in other columns. The cell is usually determined when a value is specified via NSPopupButtonCells in two other columns. When an effecting value is changed, I call reloadDataForRowIndexes:columnIndexes: to refresh the cell(s) in question. The problem is that even thought the delegate method is properly called to return the changed NSCell, the NSTableView will not redraw the cell until the row is deselected or is refreshed by some other means--such as obscuring the tableview with another window or clicking in the cell (but only when it's data cell is editable). I have also tried calling setNeedsDisplayInRect:, but that doesn't work either.
Oddly, it seems to work fine when called from an action method assigned to the NSMenuItems level of a particular NSPopupButtonCell, but not when called from an action method assigned to the NSPopupButtonCell itself. Although I did try to specify the action for the individual NSMenuItems in the other popup, but that didn't work either. The main difference between the two is that one is specified via Interface Builder and the other is generated in code.
Code is below. Any help is appreciated,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
// this method seems to work as expected
- (IBAction)selectColumn:(id)sender
{
// set expression value
ClauseExpression *expression = [self clauseExpressionForRow:[queryTableView selectedRow]];
[expression setColumn:[[sender representedObject] description]];
// set in column cache
if( [sender representedObject] )
{
// different also means clear join operand
if( [columnCache objectAtIndex:[queryTableView selectedRow]] != [sender representedObject] )
{
[columnCache replaceObjectAtIndex:[queryTableView selectedRow] withObject:[sender representedObject]];
if( [queryTableView selectedRow] > (NSInteger)[[selectQuery whereClause] countOfExpressions] )
{
JoinClause *join = [selectQuery objectInJoinClausesAtIndex:([queryTableView selectedRow]-[[selectQuery whereClause] countOfExpressions]-1)];
[[join joinExpression] setOperand:[ClauseOperand nullOperand]];
[join setJoinTable:nil];
}
}
// only for WHERE expressions, string columns should default to ILIKE
if( [queryTableView selectedRow] < (NSInteger)[[selectQuery whereClause] countOfExpressions] && [[sender representedObject] attributeType] == NSStringAttributeType && [[expression comparator] isEqualToString:@"="] )
[expression setComparator:@"ILIKE"];
}
else
{
[columnCache replaceObjectAtIndex:[queryTableView selectedRow] withObject:[NSNull null]];
}
// column changes may change comparator and operand displays
[queryTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:[queryTableView selectedRow]] columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(3, 2)]];
}
// this one does not
- (IBAction)selectComparator:(id)sender
{
// clear operand
[[self clauseExpressionForRow:[queryTableView selectedRow]] setOperand:[ClauseOperand nullOperand]];
// comparator changes may change operand displays
[queryTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:[queryTableView selectedRow]] columnIndexes:[NSIndexSet indexSetWithIndex:4]];
}
// the most relevant part of this method would be the part immediately under "case 4:"
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
// most rows are not group rows
if( tableColumn )
{
ClauseExpression *expression = [self clauseExpressionForRow:rowIndex];
// what we do depends on column
switch( [tableView columnWithIdentifier:[tableColumn identifier]] )
{
case 0:
// don't return conjunction pop only if we don't have one
if( ! [expression conjunction] )
{
NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:@""];
[cell setEditable:NO];
return [cell autorelease];
}
break;
case 4:
{
// show operand only if column selection is non-null and comparator is not a null type
if( [[expression comparator] rangeOfString:@"NULL"].location != NSNotFound )
{
NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:@""];
return [cell autorelease];
}
else if( [columnCache objectAtIndex:rowIndex] != [NSNull null] )
{
// value vs join
if( rowIndex < (NSInteger)[[selectQuery whereClause] countOfExpressions] )
{
// value operand depends on column type
switch( [[columnCache objectAtIndex:rowIndex] attributeType] )
{
case NSStringAttributeType:
case NSInteger16AttributeType:
case NSInteger32AttributeType:
case NSInteger64AttributeType:
case NSDecimalAttributeType:
case NSDoubleAttributeType:
case NSFloatAttributeType:
case NSDateAttributeType:
{
NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:@""];
[cell setEditable:YES];
[cell setPlaceholderString:@"Enter value here"];
return [cell autorelease];
break;
}
case NSBooleanAttributeType:
{
NSButtonCell *cell = [[NSButtonCell alloc] initTextCell:@"Yes (True/On)"];
[cell setButtonType:NSSwitchButton];
[cell setTarget:self];
[cell setAction:@selector(specifyOperand:)];
return [cell autorelease];
break;
}
}
}
else
{
NSPopUpButtonCell *cell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
[cell setAutoenablesItems:NO];
[cell setControlSize:NSSmallControlSize];
[cell setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
[cell setBordered:NO];
return [cell autorelease];
}
}
else
{
// otherwise blank
NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:@""];
return [cell autorelease];
}
break;
}
}
}
else if( [self tableView:tableView isGroupRow:rowIndex] )
{
NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:@""];
return [cell autorelease];
}
// return default
return [tableColumn dataCellForRow:rowIndex];
}
_______________________________________________
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