uitableview - Xamarin throws NullReferenceException when using custom UITableViewCell in iOS -


i having similar problem 1 discussed @ xamarin custom uitableviewcell throws system nullreferenceexception.

nevertheless, after following answer there, issue has not been solved.

i have custom uitableview boardlistcell. in storyboard, have uitableview. accessible in viewcontroller via outlet tableview.

in view controller, data. tableview.source = new boardstableviewsource(sourcedata);

my boardstableviewsource:

using system; using system.collections.generic; using foundation; using uikit;          public class boardstableviewsource : uitableviewsource         {             private list<list<object>> data;             boolean normalboards;              public boardstableviewsource (list<list<object>> data, bool normalboards)             {                 this.data = data;                 this.normalboards = normalboards;             }              public list<list<object>> getdata()             {                 return data;             }              public override nint rowsinsection (uitableview tableview, nint section)             {                 return data.count;             }              public override string titleforheader (uitableview tableview, nint section)             {                 return "header";             }              public override string titleforfooter (uitableview tableview, nint section)             {                 return "footer";             }              public override uitableviewcell getcell (uitableview tableview, nsindexpath indexpath)             {                 boardlistcell cell = (boardlistcell)tableview.dequeuereusablecell("boardtablecell");                  list<object> celldata = data [indexpath.row];                  cell.setdata("1","!"); //i have simplified data example              }         }     } 

when debugging, nullreference exception on cell.setdata() line.

in storyboard, have boardlistcell's identifier set boardtablecell.

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 static boardlistcell create ()     {         return (boardlistcell)nib.instantiate (null, null) [0];     }      public void setdata(string top, string bottom)     {         this.exp.text = top;         this.playtime.text = bottom;     } } 

exp , playtime outlets uilabel's. have deleted , re-added outlets, hasn't changed anything.

i don't know problem is. thing can think of because using uitableview made storyboard , accessing via outlet. nevertheless, don't know problem is...

dequeuereusablecell return null if can't find suitable cell reuse. need explicitly check before referencing cell:

boardlistcell cell = (boardlistcell)tableview.dequeuereusablecell("boardtablecell");  if (cell == null) {   cell = new boardlistcell(); }  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -