Difference between revisions of "iOSTable.CreateCustomCell"

From Xojo Documentation

(Sample Code)
 
Line 43: Line 43:
 
<rbcode>
 
<rbcode>
 
Var cell As iOSTableCellData = table.CreateCustomCell(GetTypeInfo(MyTableCell))
 
Var cell As iOSTableCellData = table.CreateCustomCell(GetTypeInfo(MyTableCell))
Var container As MyCellContainer = MyCellContainer(cell.Control)
+
Var container As MyTableCell = MyTableCell(cell.Control)
 
container.NameLabel.Text = "Some Text"
 
container.NameLabel.Text = "Some Text"
 
Return cell
 
Return cell
Line 52: Line 52:
 
Table1.AddSection("")
 
Table1.AddSection("")
 
Var cell As iOSTableCellData = Table1.CreateCustomCell(GetTypeInfo(MyTableCell))
 
Var cell As iOSTableCellData = Table1.CreateCustomCell(GetTypeInfo(MyTableCell))
Var container As MyCellContainer = MyCellContainer(cell.Control)
+
Var container As MyTableCell = MyTableCell(cell.Control)
 
container.NameLabel.Text = "Some Text"
 
container.NameLabel.Text = "Some Text"
 
Table1.AddRow(0, cell)
 
Table1.AddRow(0, cell)

Latest revision as of 14:05, 4 December 2019

Method

iOSTable.CreateCustomCell(controlClass As Xojo.Introspection.TypeInfo) As iOSTableCellData

Supported on Mobile (iOS).

Creates or reuses a table cell that uses a custom control that is based on iOSCustomTableCell. If there is no view to reuse, the cell's control will be instantiated from the passed type information.

Parameters

Parameter Description
controlClass The type of the iOSCustomTableCell subclass that will be displayed in the custom cell.

Notes

This is also usable by applications that use AddRow instead of data sources with the caveat that no reuse is possible. This is not recommended for performance reasons and users needing more than a screen's worth of rows should use a data source. If the number of rows with custom controls exceeds a certain threshold the framework will log a message in the debugger to advise users of the situation.

Exceptions

Exception Description
NilObjectException If controlClass is Nil.
InvalidArgumentException
  • If controlClass is not referring to a class or if the class has no default constructor to invoke.
  • If controlClass does not inherit from iOSControl.

Sample Code

MyTableCell is a subclass of iOSCustomTableCell that contains several controls, including a label called NameLabel. This code adds MyTableCell as a custom cell in the table and is in the RowData method of class that implements iOSTableDataSource:

Var cell As iOSTableCellData = table.CreateCustomCell(GetTypeInfo(MyTableCell))
Var container As MyTableCell = MyTableCell(cell.Control)
container.NameLabel.Text = "Some Text"
Return cell

This code directly adds MyTableCell as a custom cell to a table using the AddRow method:

Table1.AddSection("")
Var cell As iOSTableCellData = Table1.CreateCustomCell(GetTypeInfo(MyTableCell))
Var container As MyTableCell = MyTableCell(cell.Control)
container.NameLabel.Text = "Some Text"
Table1.AddRow(0, cell)

See Also

iOSCustomTableCell class