I have a tableView, with 3 columns containing NSTextFieldCell. Everything is populated with bindings.
The text of the cells of one of the column is computed and is not editable directly.
For this column, I would like when the cell goes into edit mode, to display a button or a custom view instead of the textField.
Said in an other way, I want an NSCell that is a NSTextFieldCell when not being edited, and a NSButtonCell (or a custom view) when being edited.
Any hint to move on to this?
Here is what I tried, without success:
- Try #1:
I subclassed a NSTextFieldCell
and override fieldEditorForView:
like shown below => problem is the NSButton I'm returning does not respond to setDelegate:
and probably many other stuff.
- (NSTextView *)fieldEditorForView:(NSView *)aControlView {
NSTableView *tableView = (NSTableView *) aControlView;
// Manually computing column and row index for testing purposes
NSButton* button = [[NSButton alloc] initWithFrame:[tableView frameOfCellAtColumn:2 row:2]];
return (NSTextView *)button;
}
- Try #2:
Subclass NSTextFieldCell
and override drawWithFrame: inView:
=> this method is only used to draw the cell when not in edit mode.
- Try #3:
This lead has some potential, but I'm obviously missing something here.
Implement windowWillReturnFieldEditor: toObject:
in my window's delegate, and return a custom field editor.
I seem to be on the right track, but I missed something. The argument anObject is never my custom cell (I double checked and it's defined properly in the XIB).
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
{
if ([anObject isKindOfClass:[NSCellTextAndButtonAtEditTime class]])
{
NSLog(@"Going there");
NSButton* button = [[NSButton alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
button.title = @"test";
return button;
}
return nil;
}