简体   繁体   中英

How to know whether NSTableView is in editing?

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?

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).

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.

Why not just check edited​Row ?

let isBeingEdited = yourTable.edited​Row != -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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM