I modify the source data of a NSTableView
by directly selecting the cells ( NSTextFieldCell
) and editing the text in it.
I need to perform some operations on a cell before and after a cell is edited. I perform such operations before the editing in:
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
But where can I perform the operations post editing?
Thanks
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
For your app to edit the content of an NSCell-based table view, you implement the tableView:setObjectValue:forTableColumn:row: data source protocol method. This method is similar to tableView:objectValueForTableColumn:row:, which provides the data for the table view, but instead of requesting that you return a value for the specified row and column, it provides the new value for that row and cell
Let google search for nstableview edit change and you will get a lot of detailed answers.
To make it short: use (some of) the following (and similar) delegate methods:
- (void)controlTextDidEndEditing:(NSNotification *)obj
- (void)controlTextDidChange:(NSNotification *)aNotification
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
and test them to show what are appropriate for your application:
- (void)controlTextDidEndEditing:(NSNotification *)obj
{
NSDictionary *userInfo = [obj userInfo];
NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
NSLog(@"controlTextDidEndEditing %@", [aView string] );
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSDictionary *userInfo = [aNotification userInfo];
NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
NSLog(@"controlTextDidChange >>%@<<", [aView string] );
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
NSLog(@"control: textShouldEndEditing >%@<", [fieldEditor string] );
return YES;
}
You can do this because the cells of the NSTableView
are NSTextFieldCell
s;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.