Stopping edition of a NSTableView's row after hitting return
-
Hi list,
I'm using a NSTableView with custom cells (subsclass of NSTextFieldCell) which can be edited.
When I double-click on a cell, it's been edited normally. But when I hit enter to validate the change, the edition continues and the next cell si been edited.
I would like the edition to stop. So, inside tableView:setObjectValue:forTableColumn:row:, I tried to call [tableView abortEditing], but this has no effect at all.
Trying to prevent the next cell from been edited in tableView:shouldEditTableColumn:row: is not really possible, as if I return NO for row x, the method will be called for row x+1 and so on.
Can someone tell me how to stop the edition ?
Thanks
Jérome -
On Fri, 04 Feb 2005 19:00:02 +0100, Jerome Foucher <jeromefoucher...>
said:
> I'm using a NSTableView with custom cells (subsclass of NSTextFieldCell) whichcan be edited.
>to validate the change, the edition continues and the next cell si been edited.
> When I double-click on a cell, it's been edited normally. But when I hit enter
>
> I would like the edition to stop
Check the archives. Hint: search on NSTableView and textDidEndEditing. m.
--
matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt> -
On Feb 4, 2005, at 10:00, Jerome Foucher wrote:
>Subclass NSTableView and override -textDidEndEditing: to catch returns
> Can someone tell me how to stop the edition ?
>
>
and end editing. Normally, I'd refer you to the archives, since that's
where I got much of my code. But since it took me considerable time to
actually get it working, I'll post it here for you and posterity.
- (void)textDidEndEditing:(NSNotification *)notification
{
if([[[notification userInfo] valueForKey:@"NSTextMovement"] intValue]
== NSReturnTextMovement) {
NSMutableDictionary *newUserInfo;
newUserInfo = [[NSMutableDictionary alloc]
initWithDictionary:[notification userInfo]];
[newUserInfo setObject:[NSNumber numberWithInt:NSIllegalTextMovement]
forKey:@"NSTextMovement"];
notification = [NSNotification notificationWithName:[notification
name]
object:[notification object]
userInfo:newUserInfo];
[super textDidEndEditing:notification];
[newUserInfo release];
[[self window] makeFirstResponder:self];
//Notification that table view has ended all editing
[[NSNotificationCenter defaultCenter]
postNotificationName:PFTableViewDidEndAllEditingNotification
object:self];
//Delegate endEditing
id delg = [self delegate];
SEL ds = @selector(tableViewDidEndAllEditing:);
if([delg respondsToSelector:ds]) [delg performSelectorOnMainThread:ds
withObject:self waitUntilDone:NO];
}
else {
[super textDidEndEditing:notification];
}
}
Note that everything from the "//Notification..." comment to the end of
the block is my own code added for my own purposes, and is not required
in order to do what you want.
Larry Fransson
Seattle, WA -
On 4 févr. 05, at 21:43, Larry Fransson wrote:
> Subclass NSTableView and override -textDidEndEditing: to catch returns
> and end editing. Normally, I'd refer you to the archives, since
> that's where I got much of my code. But since it took me considerable
> time to actually get it working, I'll post it here for you and
> posterity.
Thanks a million. I think it would be a good idea to post that code for
a tutorial on some Cocoa sites like Cocoa Dev Central....
As for the archives, I have to admit that I did not search the archives
correctly, as I tried this morning looking for NSTableView + editing
and got the answer in a few minutes.
My bad.
Jérome



