Dynamic iOSCustomTableCell

I’m trying to figure out how to create and populate a iosCustomTableCell with fields and data dynamically. My limited brain cells can’t figure it out. Can anyone point me in the right direction or to an example. Thanks.

You don’t create the fields themselves on the fly. Drag one from the library into the navigator and place your controls using the layout editor. Then in the place where you are populating the list, you ask the table to create one for you…

dim cell as iOSCustomDataCell = table.CreateCustomCell(GetTypeInfo(YourCustomCell))
Then you populate the cell the way you want and return it (if using a data source) or insert it directly into the table.

The reason for this extra craziness is that iOS reuses objects to shrink the memory footprint and increase the speed.

Also see: Working with Tables

And the example here:
Examples/iOS/Controls/Table/CustomCellsAndScroll

Thanks Greg and Paul, I have looked at working with tables and am using them in another app but in this case I’m connecting to a data source with template info and I don’t know in advance what the layout will be, how many fields and their positions/sizes. So I can’t create the the layout with the layout editor.

Ok. Using the CustomCellsAndScroll example I removed the TeamNameLabel and changed RowData to:
Dim customCell As TeamCustomCell = TeamCustomCell(cell.Control)

dim itf as new iostextfield
//test without layout constraint for the moment
itf.Text= teams(row)
customcell.AddControl(itf)

it works but … should it?

You have to create the layout in one or many customCell. Don’t add control to the cell on the fly. It will be reused and if you don’t need that control you will have some problem…

Here is a tutorial (in Spanish, sorry) about how to use a iOSTable that combines two iOSCustomTableCell. It would be easy to combine more custom cells on the fly.

Javier

Antonio, you wrote “You have to create the layout in one or many customCell.” Now either I’m not understanding what you are saying - that’s ok I’m used to not grasping things immediately - or I haven’t really explained my problem properly.
I am connecting to tom, dick or Harry’s database. In that database, table x,y or z they have defined various templates to display data in entry forms or lists. I want to reproduce those forms/lists on the iPhone. My app is suppose to connect to their database, and retrieve the template info and recreate the layout (fields labels etc…). I can do this for entry forms - I now want to do this for lists ie in a table. If I don’t know beforehand what the layout is then I need to create the customCells as and when I receive the info.
Sorry for the long post…

Could you just make a series of textfields and just use them for different fields each time?

As Greg said, you have to create cells for each atomic group of data (for example a textField and a label to explain it, a datePicker and a label and so on)
as you do when you show data with standard cells, your datasource must be coherent with the object you are using (it means if you edit a record, each row should be a field)

Since cells are reused you should not use them as the source of your edit, you have to build some callback mechanism (delegate for example) to update the datasource as you edit a cell

when you have done use a button on the toolbar to save the data from the datasource (or save as you edit or whatever other mechanism you want to use)

The first time you create it, you will find it complicated. When you start to reuse your components you will find this technique really simple.

Thanks everyone for your help. I’ll try out your suggestions.