Yun
Yun

Reputation: 5473

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?

Upvotes: 0

Views: 1168

Answers (3)

John
John

Reputation: 1467

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.

Upvotes: 0

Yun
Yun

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

Michael Dautermann
Michael Dautermann

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

Related Questions