Note that there are some explanatory texts on larger screens.

plurals
  1. POLabel in custom cell is null when populating UITableViewController
    primarykey
    data
    text
    <p>I'm using Xamarin.iOS to build an iOS app. I'm using a storyboard and have created a <code>UITableViewController</code> with a grouped table using custom cells. The cell contains a label to which I want to assign a value.</p> <p>Overriding the getcell method in the datasource to set the text property of the label throws a null exception and I can't find why? I've checked the outlet and it's there. Any tips on how to find the error?</p> <pre><code>public partial class NameListScreen : UITableViewController { MyTableSource _source = null; public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); LoadNameList(); } void LoadNameList () { var service = new MyService(); var names = service.GetAllNames(); _source = new MyTableSource(names); this.TableView.Source = _source; } } public class MyTableSource : UITableViewSource { protected List&lt;string&gt; _names; protected string _cellIdentifier = "MyCell"; public MyTableSource (List&lt;string&gt; items) { _names = items; } public override int RowsInSection (UITableView tableview, int section) { return _names.Count; } public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { // Request a recycled cell to save memory var cell = (MyTableCell) tableView.DequeueReusableCell(_cellIdentifier); // If there are no cells to reuse, create a new one if (cell == null) cell = new MyTableCell(); cell.UpdateCell(indexPath, _names[indexPath.Item]); return cell; } } public partial class MyTableCell : UITableViewCell { public MyTableCell () : base () { } public MyTableCell (IntPtr handle) : base (handle) { } public void UpdateCell(NSIndexPath indexPath, string name) { this._indexPath = indexPath; this._id = track.TrackId; this.NameLabel.Text = name; //This row throws exception as NameLabel is null, why? } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload