2020-08-12 MATLAB App Designer——?jiǎng)h除既有的彈窗
1、目標(biāo)
? ? ?在編程中想實(shí)現(xiàn)一個(gè)彈窗(uifigure控件)多次彈出
如果該彈窗存在則先關(guān)閉在重新生成
2、刪除方法
APP Designer中刪除彈窗控件采用“delete”命名,假設(shè)彈窗句柄名稱為app.FirstTreeNode.Figure,則刪除命令為:delete(app.FirstTreeNode.Figure)
3、進(jìn)階方法
?3.1?在編程階段,在刪除該彈窗時(shí)同時(shí)清空該彈窗Children控件,實(shí)現(xiàn)思路,是指定一個(gè)主變量,如app.FirstTreeNode,設(shè)置彈窗句柄? app.FirstTreeNode.Figure=uifigure(...);設(shè)置彈窗內(nèi)控件其他句柄,如tree控件:app.FirstTreeNode.Object.Tree = uitree(...),?如Spinner控件:?app.FirstTreeNode.Object.Spinner = uispinner(...)。這樣在刪除彈窗控件時(shí)同時(shí)刪除該彈窗內(nèi)的控件,降低內(nèi)存的占用避免回調(diào)不知名的沖突。
3.2實(shí)現(xiàn)代碼的通用性,一個(gè)函數(shù)可以刪除多個(gè)指定彈窗句柄,用到eval函數(shù)與strcat函數(shù)
function [ ] = ifun_DeletcFigureFcn(app,FigureHandleStr)?
% 刪除既有的彈窗Figure和該句柄下控件Object合集
%?app 不可刪除
%?FigureHandleStr 彈窗句柄字符串 % eg:'app.FirstTreeNode.Figure'
? ? ? ? ? ? try
? ? ? ? ? ? ? ? ID = strfind(FigureHandleStr,'.');
? ? ? ? ? ? ? ? FigureHandleStr = FigureHandleStr(1:ID(end)-1);
? ? ? ? ? ? ? ? if? ?eval(strcat('isfield(',FigureHandleStr,',',39,'Figure',39,')&&...
~isempty(',FigureHandleStr,'.Figure )'))
? ? ? ? ? ? ? ? ? ? eval(strcat('delete(',FigureHandleStr,'.Figure)')); % 刪除彈窗
? ? ? ? ? ? ? ? ? ? eval(strcat(FigureHandleStr,'.Object=[];')); % 刪除控件信息
? ? ? ? ? ? ? ? end
? ? ? ? ? ? catch
? ? ? ? ? ? end
? ? ? ? end