The outputs in Xamarin custom TableViewCell are zero

I am trying to use a custom UITableViewCell. I can get a cell instance so that it is not null. However, all UILabel outputs in the cell are zero. This way I get a null pointer exception.

This is similar to the iOS custom TableViewCell class subviews return null and the Label in the custom cell is NULL when populating the UITableViewController . However, none of the solutions resolved my issue. They suggest making sure that the identifier matches what it does. They also tell me that I register cells for reuse, which I also do.

I made sure that my identifier in the Xib cell file matches what I'm using.

View table in Xcode with id

In my Source class:

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
    tableView.RegisterClassForCellReuse(typeof(BoardListCell), new NSString(BoardListCell.Key));
    var cell = (BoardListCell) tableView.DequeueReusableCell(BoardListCell.Key);
    if (cell == null) 
    {
        var nib = UINib.FromName(BoardListCell.Key, NSBundle.MainBundle);
        cell = (BoardListCell)nib.Instantiate (null, null) [0];
    }

    cell.setData("top", "not top"); //Sample data
    return cell;
}

BoardListCell:

public partial class BoardListCell : UITableViewCell
{
    public static readonly UINib Nib = UINib.FromName ("BoardListCell", NSBundle.MainBundle);
    public static readonly NSString Key = new NSString ("BoardListCell");

    public BoardListCell() : base()
    {

    }

    public BoardListCell (IntPtr handle) : base (handle)
    {

    }

    public void setData(String top, String bottom)
    {
        exp.Text = top;
        playTime.Text = bottom;
    }
}

, . . , , xcode, ..

+4

Source: https://habr.com/ru/post/1628658/


All Articles