xamarin.ios - Xamarin CollectionViewCell not instantiating from storyboard -


i collaborating designer styles elements on xamarin project storyboard. have trouble referencing placed elements in code. outlets created, in uicollectionviewcell uilabels etc not instantiated. here code simple test app demonstrate problem.

the xamarin generated code-behind:

[register ("cardcell")] partial class cardcell {     [outlet]     [generatedcode ("ios designer", "1.0")]     uilabel txtname { get; set; }      void releasedesigneroutlets ()     {         if (txtname != null) {             txtname.dispose ();             txtname = null;         }     } } 

my attempt set ui properties causes crash:

public partial class cardcell : uicollectionviewcell {     public cardcell (intptr handle) : base (handle)     {     }       public void update(string name)     {         txtname.text = name;  // throws exception here, because textname null     } } 

the view controller delegate methods:

public partial class testcollectioncontroller : uicollectionviewcontroller {     static nsstring cardcellid = new nsstring ("cardcell");      string[] cards = new string[] {"red", "green", "white", "blue", "pink", "yellow"};      public testcollectioncontroller (intptr handle) : base (handle)     {     }      public override void viewdidload ()     {         base.viewdidload ();          collectionview.registerclassforcell (typeof(cardcell), cardcellid);      }      public override nint numberofsections (uicollectionview collectionview)     {         return 1;     }      public override nint getitemscount (uicollectionview collectionview, nint section)     {         return (nint)cards.length;     }      public override uicollectionviewcell getcell (uicollectionview collectionview, nsindexpath indexpath)     {         cardcell cell = (cardcell)collectionview.dequeuereusablecell (cardcellid, indexpath);          var card = cards [indexpath.row];          cell.update(card);          return cell;     } } 

i have tried both xamarin ios designer , xcode's interface builder, not make difference. appreciated.

examples of collection views driven storyboard quite scarce, found this one , teased through meticulously till discovered did not include call register class cell. so, remove line:

collectionview.registerclassforcell (typeof(cardcell), cardcellid); 

and works expected.

i following this recipe , other examples, had call included, needed when don't use storyboard.


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -