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 uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by