App Designer: Use a button in one .mlapp file to open a specific UItab in a different .mlapp file

조회 수: 3 (최근 30일)
I would like to use a button in one .mlapp file to open a specific UItab in a different .mlapp file in app designer. When I use 'appname.uitab_2' I get the error "The property 'uitab_2' in class 'appname' must be accessed from a class instance because it is not a Constant property."
Any help would be appreciated.

답변 (1개)

Elizabeth Reese
Elizabeth Reese 2017년 8월 14일
Let the app with the button be called app1 and the app with the tab group be called app2. In app2, let the tab group be called TabGroup and the two tabs be called Tab1 and Tab2.
Within app1,
  • Add a property (I will call it app2_handle)
  • Add a startupFcn callback to the UIFigure
  • In the startupFcn, call the constructor for app2 and assign the handle to app2_handle.This function in app1 looks like:
function startupFcn(app)
app.app2_handle = app2();
end
This makes app1 open an instance of app2. Now you can manipulate app2 from app1.
  • Add a ButtonPushed callback to the button in app1.
  • In ButtonPushed, use app2_handle to manipulate the SelectedTab. An example of this function could be:
% Button pushed function: Button
function ButtonPushed(app, event)
selected = app.app2_handle.TabGroup.SelectedTab;
if (selected == app.app2_handle.Tab1)
app.app2_handle.TabGroup.SelectedTab = app.app2_handle.Tab2;
else
app.app2_handle.TabGroup.SelectedTab = app.app2_handle.Tab1;
end
end

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by