I try to convert an ‘old’ iOS example (using AddRow(section, value)) to an application based on the use of iOSTableDataSource. I have two sections. The section titles are displayed well but all names are added to both sections. The following code is used in RowData:
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(TableCustomCell))
Var customCell As TableCustomCell = TableCustomCell(cell.Control)
customCell.StudentName = Names(row)
Return cell```
But how can I add code into RowData to decide in which section the name must displayed? An easy example could be to store all names starting with the character 'A' in section 0 and all other names in section 1.
Select Case section
Case 0
If Names(row).Left(1) = "A" Then
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(TableCustomCell))
Var customCell As TableCustomCell = TableCustomCell(cell.Control)
customCell.StudentName = Names(row)
Return cell
End If
Case 1
If Names(row).Left(1) <> "A" Then
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(TableCustomCell))
Var customCell As TableCustomCell = TableCustomCell(cell.Control)
customCell.StudentName = Names(row)
Return cell
End If
End Select
Names starting with ‘A’ are in section 0 the other names are in section 1. That’s correct, but in both sections there are empty rows for the names placed in the other section. What am I doing wrong?
When the If evaluates to False, you are skipping a cell so you end up with blank cells. You could create new arrays like NamesA() and NamesNotA() and use those here.
You can also move the Return cell to the bottom and not duplicate it.
@Jeremie_L Indeed, you have to return the number of elements in both sections. But only this change doesn’t solve the problem. @Art_Gorski Indeed, you have to create arrays (or a dictionary) with the elements split up for both sections.
A combination of both replies solves the problem. Thank you for your help!
// Part of the iOSMobileTableDataSource interface.
Select case section
Case 0
Return NamesA.Count
Case 1
Return NamesNotA.Count
End Select
RowData:
// Part of the iOSMobileTableDataSource interface.
Select Case section
Case 0
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(TableCustomCell))
Var customCell As TableCustomCell = TableCustomCell(cell.Control)
customCell.StudentName = NamesA(row)
Return cell
Case 1
Var cell As MobileTableCellData = table.CreateCustomCell(GetTypeInfo(TableCustomCell))
Var customCell As TableCustomCell = TableCustomCell(cell.Control)
customCell.StudentName = NamesNotA(row)
Return cell
End Select