简体   繁体   中英

Preventing updates to NSTableView while editing

I have an NSTableView that has one column of editable fields. Cell editing works fine, and my delegate routines get the update and can act on them as needed. The problem is that there is other code that updates values in the table based on timer or asynchronous (socket) input. When an updates event happens while editing is in progress, the update overwrites the user input.

I'm trying to use the delegate methods to block updates with an instance variable lock:

   - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;
{
    tableEditInProgress = YES;
    return YES;
}

- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
    tableEditInProgress = NO;
    return YES;
}

- (void)controlTextDidBeginEditing:(NSNotification *)aNotification
{
    tableEditInProgress = YES;
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
    tableEditInProgress = NO;   
}

This only seems to work if the user actually types new text in the field before the update happens. I want updates to be blocked as soon as the user gets an edit cursor in the field (double click field contents).

I'm probably just using the wrong delegate methods.

TIA

joe

Try ditching all this stuff, and try this instead:

When you want to check whether the table is currently being edited, call [tableView currentEditor]; If this is non-nil, the table view is being edited. If it's nil, it's not being edited. That is:

BOOL tableEditInProgress = ([tableView currentEditor] != nil);

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