Saving TextField data in a CustomTableCell of iOSTAble?

Hi all,

I have an iOSTable that contains custom cells in it. Each custom cell has a textfield. And then I have a Save button outside of the the listbox which will call an SQL update to the server.

Inside the Save button’s Action Event I did something like this:
Dim cell As CustomCell = CustomCell(table.RowData(0,1).Control)

Dim cellTextData As Text = cell.Text_Data

CustomCell is a iOSCustomTableCell class that contains a property called Text_Data which gets saved whenever the textfield’s text is changed.

So whenever I did a textfield change, the data would not get saved and it would still display the old data back. Any ideas would be appreciated.

Not the best approach.

The cell on iOS (not only with Xojo) are reused. So the cell content is not a good way to get data.
Cells should reflect your datasource content.

You should use some callback to update the data back to your current datasource and when you save, save your datasource

I see, so I should update my datasource again when someone uses TextChange Event?

yes otherwise if you have many cells and scroll again to the modified one you will see the original text.

Think at the cell as a view “only” but with interaction. Real data are in the datasource.

I have my datasource saved in a Window property and the custom cells are saved in an iOSTable of the same Window. How would I change the datasource from inside the custom cells? I tried to use Self.parent.parent but it wouldn’t work.

Any ideas?

Use a delegate function (callback) with the information that let you modify your data source in the right way:

something like:
updateDelegate(rowTag as text, type as text, value as Auto)

then in the cell you need 2 props:
rowTag as text
callback as updateDelegate

in the “change” event of a control in your cell:
callback.invoke(rowTag, “actionname”, me.value or me.text or whatever value you need)

when you set the data in the cell (Datasource RowData) with some thing like:
myCell.rowtag=“something unique”
myCell.callback=weakAddressOf updateAction

where updateAction is a sub (with signature updateDelegate)
in this sub you have 2 info to locate what you have to do: rowTag and type and the value to memorize.

For example:
you show a list of phoneNumbers (each with its ID) from a DB and in the cell you have a textField to change the number and a switch to tell if the number is “special”
in the textField textChange you call callback.invoke(ID, “changeNumber”, me.text)
in the switch valueChanged you call callback.invoke(ID, “isSpecial”, me.value)

so your updateAction can do:
select case type
case “changeNumber”
//Change the phoneNumber of item identified by ID

case “isSpecial”
//Change the special status of item identified by ID
end select

As usually more complicated to explain than to code…