我们正在编写一个带有几个下降的程序,以通过数据进行排序。这是一个体面的数据集,并且下拉是动态生成的。结果,当您更改下拉舞时,您必须等待一到五秒钟,然后选择下一个下拉纸,或者将整个事情拧紧。因此,我写了一个小功能,可以禁用所有UI元素(将启用属性设置为关闭)。
问题在于它在下拉回调功能中无法可靠地工作。
function deactivate_pulldowns(handles)
set(handles.first_data_field_pulldown,'enable','off');
set(handles.first_key_data_list_pulldown,'enable','off');
set(handles.second_data_field_pulldown,'enable','off');
function first_data_field_pulldown_Callback(hObject, eventdata, handles)
%deactivate the pulldowns until processing is complete
deactivate_pulldowns(handles);
%wipe out the old pull down if it exists
try
[dummy, dummy] = size(handles.first_field_reduced_key_data);
handles.first_field_reduced_key_data = '';
clear handles.first_field_reduced_key_data
catch
% ... This is pretty long and does a bunch of processing and takes time
因此,以上不起作用。但是,如果我在Deactivate_pulldowns呼叫后添加了一个消息框,则可以正常工作。
function first_data_field_pulldown_Callback(hObject, eventdata, handles)
%deactivate the pulldowns until processing is complete
deactivate_pulldowns(handles);
msgbox('test1');
%wipe out the old pull down if it exists
try
[dummy, dummy] = size(handles.first_field_reduced_key_data);
handles.first_field_reduced_key_data = '';
clear handles.first_field_reduced_key_data
catch
% ... This is pretty long and does a bunch of processing and takes time
这将像我期望的那样停用所有下拉。这里发生了什么!?
看起来您需要强制用户界面对象更新。尝试drawnow
代替虚拟消息框:
drawnow('update')
或单独使用drawnow
的完整事件队列齐平。