简体   繁体   English

编辑时禁止更新NSTableView

[英]Preventing updates to NSTableView while editing

I have an NSTableView that has one column of editable fields. 我有一个NSTableView具有一列可编辑字段。 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 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]; 如果要检查当前是否正在编辑表,请调用[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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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