I created 2 custom UITableViewCell's in Interface builder and when I dequeue the cells, they are acting as Default cells. I have 2 sections, the first section should be the header labels and they are not connected to any code so I don't need to change their values (set in IB). Second section will contain multiple rows and be connected to data, so I need to set each labels value.
A few things to note:
- I have double checked that the re-use Identifier is correct in the interface as well as in code
- And finally, I have registered the the cells like so:
tableView.RegisterClassForCellReuse(typeof(TableInfoDataCell), TableInfoDataCell.cellID);
Some code:
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
try
{
switch (indexPath.Section)
{
case 1: // Situaltional Data
{
tableView.RegisterClassForCellReuse(typeof(TableInfoDataCell), TableInfoDataCell.cellID);
TableInfoDataCell cell = (TableInfoDataCell)tableView.DequeueReusableCell(TableInfoDataCell.cellID, indexPath);
if (cell == null) { cell = new TableInfoDataCell(TableInfoDataCell.cellID); }
//cell.SetSuccessCriteria = "N";
cell.BackgroundColor = UIColor.Green;
cell.TextLabel.Text = "Data Cell";
return cell;
}
default: // Header Cells
{
tableView.RegisterClassForCellReuse(typeof(TableInfoHeaderCell), TableInfoHeaderCell.cellID);
TableInfoHeaderCell cell = (TableInfoHeaderCell)tableView.DequeueReusableCell(TableInfoHeaderCell.cellID, indexPath);
if (cell == null) { cell = new TableInfoHeaderCell(TableInfoHeaderCell.cellID); }
cell.BackgroundColor = UIColor.Red;
cell.TextLabel.Text = "Header Cell";
return cell;
}
}
}
catch (Exception ex)
{
Console.WriteLine("EXCEPTION: " + ex.Message);
return null;
}
}
What the table looks like when ran, versus what it should look like (based on Interface Builder design):
Custom UITableViewCell class
Both header and data cells are pretty much identical at this point since neither of them will display when loading the tableview.
question from:https://stackoverflow.com/questions/65877898/xamarin-ios-custom-cell-not-showing-labels-from-interface-builder