How to specify a callback function for the CellSelectionCallback property for runtime created Tables in App Designer?

3 次查看(过去 30 天)
In App Designer:
Suppose that a TabGroup is created in App Designer's Design View, and that new tabs are simply added at runtime:
hTab = uitab(app.TabGroup,'Title',name_string);
Then suppose that a table is created as a child of the new tab, with a function specified for the CellSelection callback:
hTable = uitable(hTab,'CellSelectionCallback',@TableCellSelection);
The function TableCellSelection(app,event) is a private method in the app.
When the user selects some region of a successfully populated table, the following error results:
Undefined function 'TableCellSelection' for input arguments of type 'matlab.ui.control.table'.
Am I using an incorrect approach, or is this possibly a bug? Thanks.

回答(1 个)

Kevin Holly
Kevin Holly 2023-7-26
MrToad,
It seems like MATLAB cannot locate the function. You could call the function from outside the app. Please see the app and script attached.
In the example attached, I called the function with app as an input:
hTable = uitable(hTab,'CellSelectionCallback',{@TableCellSelection app});
To test to see if the function works, I had it make a label visible.
function TableCellSelection(table_handle,events,app)
app.CellSelectionworksLabel.Visible = "on";
end

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by