MobileTableCustomCell - how to access contents of cell?

I have a MobileTableCustomCell and am wondering how to access the contents.

My custom cell has a picture and a label that are set when the cell is created for the table. So… how can I access that data?

I think a brief tutorial on this control would be helpful.

Thanks to all who can get me pointed in the right direction!

It might not be the answer you’re looking for, but I keep my data in a DataSource Class which has an Array of data for each Row (in a per-Row Class). When I need the data for a Row I look up the DataSource and not the Table itself.

Not sure if it’s possible to save picture files in a DataSource class, but that is a good idea.

I guess I can just save the pics to a directory and set the file name using the DataSource.

I use an array of objects to populate the table using a datasource. This object can contain a unique picture.

Here’s a snipped example of how I populate the custom table cell using a datasource (only the code for one row shown):

Public Function RowData(table As iOSMobileTable, section As Integer, row As Integer) As MobileTableCellData
// Populate a specific cell
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(PersonDetailsTableCell))
Var customCell As PersonDetailsTableCell = PersonDetailsTableCell(cell.Control)

Select Case row
Case 0
customCell.DescriptionLabel.Text = “home phone”
If People(CurrentPerson).HomePhone <> “” Then
customCell.DataLabel.Text = People(CurrentPerson).HomePhone
Else
customCell.DataLabel.Text = “”
End If
If System.Version >= “13” Then
customCell.SFSymbolsIcon.Image = Picture.SystemImage(“phone”,0,Picture.SystemImageWeights.Regular,SymbolColor,Nil)
End If
customCell.DataLabel.TextColor =ColorGroup.NamedColor(“LinkColor”)
End Select

cell.AccessoryType = MobileTableCellData.AccessoryTypes.None

Return cell
End Function

Give the tablecell some public properties and set those at creation time?

You should not save data in the MobileTableCustomCells directly (IE do not design a system where you try to obtain the info back after user interaction). The data source model allows iOS to only maintain a few cells beyond what is visible and automatically delete cells that are invisible to greatly improve performance, and the events provided by it are what you should use to create cells and handle user interaction with the table.

1 Like

…but if you only interact with visible items, their data properties will be correct, surely?
I use tags to hold ‘information I later need about this row’ and have had no issues addressing it.
I couldnt loop through 1000 items… for that I would go back to the data source… but for a quick ‘tell me something about the thing that just got selected’ , I hvent had any issues.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.