Error when getting selected cell indices - R2019b

Hi,
I'm running into an error when using the cell selection callback for a uitable. Below is how i have defined the callback function, the function and the error message i am getting.
classdef PFTable < Component
properties
Table
end
methods
function obj = PFTable(model, parent, varargin)
obj@Component(model, parent);
obj.Table = uitable('Parent', obj.Panel);
obj.Table.CellSelectionCallback = @(s, event) obj.setToSelectedCell(obj);
obj.set(varargin{:});
end
end
methods (Access = protected)
function setToSelectedCell(obj, event)
indices = event.Indices;
end
end
end
The error message i get is
Unrecognized method, property, or field 'Indices' for class 'PFTable'.
Error in PFTable/setToSelectedCell (line 69)
indices = event.Indices
Error in PFTable>@(s,event)obj.setToSelectedCell(obj) (line 13)
obj.Table.CellSelectionCallback = @(s, event) obj.setToSelectedCell(obj);
Error using matlab.ui.internal.controller.uitable.WebMWTableController/handleEvent (line 588)
Error while evaluating Table CellSelectionCallback.
Am i getting this error because the access to the function is protected?
Any advice on how to get the callback working would be great!

 採用された回答

Tristan Thompson
Tristan Thompson 2021 年 2 月 2 日

0 投票

Hi i've got the answer solved,
classdef PFTable < Component
properties
Table
end
methods
function obj = PFTable(model, parent, varargin)
obj@Component(model, parent);
obj.Table = uitable('Parent', obj.Panel);
obj.Table.CellSelectionCallback = @obj.setToSelectedCell;
obj.set(varargin{:});
end
end
methods (Access = protected)
function setToSelectedCell(obj,~,e)
indices = e.Indices;
end
end
end

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 2 日

0 投票

obj.Table.CellSelectionCallback = @(s, event) obj.setToSelectedCell(obj);
You are not passing the event into the method.

1 件のコメント

Tristan Thompson
Tristan Thompson 2021 年 2 月 2 日
When i update the callback to this
obj.Table.CellSelectionCallback = @(s, event) obj.setToSelectedCell(obj, event);
I get this error
Error using PFTable/setToSelectedCell
Too many input arguments.
Error in PFTable>@(s,event)obj.setToSelectedCell(obj,event) (line 13)
obj.Table.CellSelectionCallback = @(s, event) obj.setToSelectedCell(obj,
event);
Error using matlab.ui.internal.controller.uitable.WebMWTableController/handleEvent (line 588)
Error while evaluating Table CellSelectionCallback.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop 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