ios - GetViewForSupplementaryElement not getting called when trying to show heading in UICollectionView -


i trying setup uicollectionview within existing uiviewcontroller. working except getting title show each section - can't figure out i'm doing wrong.

my code in uiviewcontroller initiate collection view:

public partial class viewcontroller : uiviewcontroller {     //...      public override void viewdidload ()     {         base.viewdidload ();          collectionview_outlet.registerclassforcell(typeof(modifiercell), modifiercell.cellid);         collectionview_outlet.registerclassforsupplementaryview (typeof(header), uicollectionelementkindsection.header, header.headerid);         collectionview_outlet.showshorizontalscrollindicator = false;         collectionview_outlet.source = new modifierssource(this);         collectionview_outlet.backgroundcolor = uicolor.white;         collectionview_outlet.reloaddata();     }      //... } 

then have created subclass of uicollectionviewsource:

public class modifierssource : uicollectionviewsource {     viewcontroller sendervc;      public modifierssource(viewcontroller sender)     {         sendervc = sender;     }      public override nint numberofsections(uicollectionview collectionview)     {         return 2;     }      public override nint getitemscount (uicollectionview collectionview, nint section)     {         return sendervc.modifiers.count;     }      public override uicollectionviewcell getcell(uicollectionview collectionview, nsindexpath indexpath)     {         //...     }       public override uicollectionreusableview getviewforsupplementaryelement(uicollectionview collectionview, nsstring elementkind, nsindexpath indexpath)     {         var headerview = (header)collectionview.dequeuereusablesupplementaryview (elementkind, header.headerid, indexpath);         headerview.text = "supplementary view";         return headerview;       }  } 

and created:

public class header : uicollectionreusableview {     public static nsstring headerid = new nsstring("usersource1");     uilabel label;      public string text {         {             return label.text;         }         set {             label.text = value;             setneedsdisplay ();         }     }      [export ("initwithframe:")]     public header (rectanglef frame) : base (frame)     {         label = new uilabel (){             frame = new rectanglef(0,0,300,50),              backgroundcolor = uicolor.red};         addsubview (label);         backgroundcolor = uicolor.white;     } } 

i've put breakpoint on getviewforsupplementaryelement method never gets called. i've set following in storyboard:

xcode screenshot

what missing?!

after many attempts of not being able above work, manually set uicollectionviewflowlayout whilst initiating uicontainerview. seems have done trick, not sure why didn't pick settings storyboard. here working code:

public override void viewdidload ()     {         base.viewdidload ();          collectionview_outlet.registerclassforcell(typeof(modifiercell), modifiercell.cellid);         collectionview_outlet.registerclassforcell(typeof(itemoptioncell), itemoptioncell.cellid);         collectionview_outlet.registerclassforsupplementaryview (typeof(header), uicollectionelementkindsection.header, header.headerid);         collectionview_outlet.showshorizontalscrollindicator = false;          //this new bit added:         var layout = new uicollectionviewflowlayout ();         layout.headerreferencesize = new cgsize (300, 40);         collectionview_outlet.setcollectionviewlayout (layout, false);          collectionview_outlet.source = new modifierssource(this);         collectionview_outlet.reloaddata();     } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -