Answer the question
In order to leave comments, you need to log in
How does editing work in view based NSTableView?
Can anyone help explain how editing works in a view based NSTableView? I'm trying to implement a behavior where double-clicking replaces the view and shows more detailed editing of the cell's data.
I rummaged through the entire StackOverflow, read the mountain of Apple documentation, call editing on a double click ... I even learned how to replace the view, but I can’t edit the rest of the fields in the cell, editing closes immediately. As I understand it, there you need to figure out the mechanism for transferring focus from a cell to a textField through firstResponder.
Just in case: in the application I use Core Data and Cocoa Bindings.
If there is someone who really cuts in this topic, then I’m even ready to pay him money for a consultation, since this is not the last difficult issue for me that I want to thoroughly understand.
Answer the question
In order to leave comments, you need to log in
OS X, yes.
When double-clicking, the @property editingRow value changes, the table is reloaded, the view is replaced, and editing begins. You have to use both delegation and cocoa bindings at the same time. I haven't found a better way yet.
The current solution works, but only if you have one textField per cell. The rest cannot be edited, with any click, the editing mode is turned off.
I need not to edit the current solution, but to understand how this should be done in principle. I found two paragraphs on this topic
in the
Apple docks :
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// getting tableview's arraycontroller
NSArrayController *arrayController = [[tableView infoForBinding:NSContentBinding] valueForKey:NSObservedObjectKey];
// checking if task was done and assigning custom cellview
NSNumber *done = [arrayController.arrangedObjects[row] valueForKey:@"done"];
if ([done boolValue]) {
return [tableView makeViewWithIdentifier:@"done" owner:self];
} else if (self.editingRow == row) {
return [tableView makeViewWithIdentifier:@"editing" owner:self];
} else {
return [tableView makeViewWithIdentifier:@"regular" owner:self];
}
}
- (void)doubleClick:(id)sender
{
NSInteger clickedRow = [sender clickedRow];
if (clickedRow != -1) {
self.editingRow = clickedRow;
[self.somedayTableView reloadData];
[sender editColumn:0 row:[sender clickedRow] withEvent:nil select:YES];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question