Here is my StoryBoard contains with a UITableView and insert a custom TabelViewCell(StudentCell):
First, you need to check the Identifier
is setted in StoryBoard:
Then make sure using the same Cell Id in GetCell
method:
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = (StudentCell)tableView.DequeueReusableCell("Cell_ID", indexPath);
var student = Students[indexPath.Row];
cell.UpdateCell(student);
//cell.TextLabel.Text = student.FullName;
return cell;
}
Last, the custom cell code could modify as follows:
public partial class StudentCell : UITableViewCell
{
protected StudentCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
internal void UpdateCell(Student student)
{
//LabelOne/LabelTwo/LabelThree is declared from TabeleViewCell in storyboard
LabelOne.Text = student.FullName;
LabelTwo.Text = student.Course;
LabelThree.Text = student.Duration;
}
}
You not need to add AwakeFromNib method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…