Re: NSCell Subclass Editing Weirdness
Re: NSCell Subclass Editing Weirdness
- Subject: Re: NSCell Subclass Editing Weirdness
- From: Ryan Stevens <email@hidden>
- Date: Tue, 28 Jun 2005 08:01:24 -0700
On Jun 27, 2005, at 5:34 PM, Matt Ball wrote:
I have a tableView, which I have subclassed in order to draw a
gradient selection background. I then have a subclassed NSCell
which is very similar to the example "IconAndTextCell" that Apple
provides. My tableView's dataSource method queries an
NSMutableArray, and then returns values from it. Currently, when I
edit my subclassed NSCell, it works as expected for the first edit.
From then on, every time I edit a cell, every cell that I have
edited up to this point changes its text to reflect the current
cell's new title. Does anyone see anything in this code that might
be causing this?
In my tableView subclass, I have this, in order to prevent the
tableView from selecting the next row when I finish editing.
- (void)textDidEndEditing:(NSNotification *)aNotification
{
//NSTableColumn *secondCol = [[self tableColumns] objectAtIndex:
1];
//[self selectRow:([self selectedRow]-1) byExtendingSelection:NO];
//[super textDidEndEditing:aNotification];
if ([[[aNotification userInfo] objectForKey:@"NSTextMovement"]
intValue] == NSReturnTextMovement) {
// This is ugly, but just about the only way to do it.
NSTableView is determined to select and edit something else, even
the text field that it just finished editing, unless we mislead it
about what key was pressed to end editing.
NSMutableDictionary *newUserInfo;
NSNotification *newNotification;
newUserInfo = [NSMutableDictionary dictionaryWithDictionary:
[aNotification userInfo]];
[newUserInfo setObject:[NSNumber
numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];
newNotification = [NSNotification notificationWithName:
[aNotification name] object:[aNotification object]
userInfo:newUserInfo];
[super textDidEndEditing:newNotification];
// For some reason we lose firstResponder status when when
we do the above.
[[self window] makeFirstResponder:self];
}
}
And in my NSCell subclass, I have this:
- (void)endEditing:(NSText *)textObj
{
NSMutableArray *layersArray = [[NSMutableArray alloc] init];
layersArray = [[[NSDocumentController sharedDocumentController]
currentDocument] layersArray];
int row = [[self controlView] selectedRow];
int indexToQueryForTitle = row * 5;
[layersArray replaceObjectAtIndex:indexToQueryForTitle
withObject:[textObj string]];
[[self controlView] reloadData];
[super endEditing:textObj];
}
Not sure that it'll help but you might switch those last two calls
around, endEditing then reloadData.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden