Reputation: 5473
I want to check if my NSTableView is in editing or not.
I tried to use tableView: shouldEditTableColumn: row: and tableView: setObjectValue: forTableColumn: row: functions. For example:
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
isRenaming = YES;
return YES;
}
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
isRenaming = NO;
...
}
However, tableView: shouldEditTableColumn: row: function was called even when I didn't try to edit the tableview.
So, sometimes, isRenaming is remained to YES.
How to know whether NSTableView is in editing?
Upvotes: 0
Views: 1168
Reputation: 1467
Why not just check editedRow
?
let isBeingEdited = yourTable.editedRow != -1
This property does not apply to view-based table views. In a view-based table view, the views are responsible for their own editing behavior. For other tables, the value reflects the index of the row being edited or –1 when there is no editing session in progress.
Upvotes: 0
Reputation: 5473
Finally, I found the missing case.
"tableView: shouldEditTableColumn: row:" function was called when the double-click event was occured on NSTableView.
So,
- (void)tableViewDoubleClicked:(id)sender {
isRenamed = NO;
...
}
It solved the problem.
Upvotes: 0
Reputation: 89559
Set your view controller to be a delegate for the text view in your table view cell.
Then you can set "isRenaming = YES
" when the user triggers the [control: textShouldBeginEditing:]
protocol method. You can also set "isRenaming = NO
" when the user is done editing (or when they click the "done" or "save changes" button in your UI).
Upvotes: 1