ios - Dynamic Cell Height in MvvmCross -


i want override getheightforrow method, scroll works when scrolling specific cell (row).

i found example here working perfectly. because of part of code:

 public override float getheightforrow(uitableview tableview, nsindexpath indexpath)     {         if (this.offscreencell == null)         {             this.offscreencell = new itemcell();         }          var cell = this.offscreencell;          cell.updatefonts();         var item = this.model.items[indexpath.row];         cell.title = item.title;         cell.body = item.body;          cell.setneedsupdateconstraints();         cell.updateconstraintsifneeded();          cell.bounds = new rectanglef(0, 0, this.tableview.bounds.width, this.tableview.bounds.height);          cell.setneedslayout();         cell.layoutifneeded();          var height = cell.contentview.systemlayoutsizefittingsize(uiview.uilayoutfittingcompressedsize).height;         height += 1;          return height;     } 

tried translate mvvmcross project, like:

public override float getheightforrow(uitableview tableview, nsindexpath indexpath)     {         if (this.offscreencell == null)         {             this.offscreencell = new itemcell();         }          var cell = this.offscreencell;         cell.datacontext = this.model.items[indexpath.row];          cell.setneedsupdateconstraints();         cell.updateconstraintsifneeded();          cell.bounds = new rectanglef(0, 0, this.tableview.bounds.width, this.tableview.bounds.height);          cell.setneedslayout();         cell.layoutifneeded();          var height = cell.contentview.systemlayoutsizefittingsize(uiview.uilayoutfittingcompressedsize).height;         height += 1;          return height;     } 

but returning 36.5 no matters what. clue of how make it?

thanks in regards,

you might have better luck uicollectionview instead of uitableview. overall, they're more flexible table views.

if give try, you'll find it's quite easy custom heights individual items (collection views have items instead of cells).

first, need create custom uicollectionviewdelegateflowlayout:

public class thingdelegateflowlayout : uicollectionviewdelegateflowlayout {     list<thing> things;      public thingdelegateflowlayout(list<thing> things)     {         things = things;     }      // override allows dynamically size uicollectionview items     public override sizef getsizeforitem (uicollectionview collectionview, uicollectionviewlayout layout, nsindexpath indexpath)     {         return new sizef(             width: uiscreen.mainscreen.bounds.width, // set width whatever want. in case, it's screen width.             height: things[indexpath.row].height // set item height         );     } } 

then in view controller following. note important line...

thingcollectionview.delegate = new thingdelegateflowlayout(things);

...near bottom, you're assigning the custom uicollectionviewdelegateflowlayout uicollectionview:

public class thingviewcontroller : uiviewcontroller {     private list<thing> things;      public thingviewcontroller()     {         things = getthings();     }      // gets list of sweet hair dos     private list<thing> getthings()     {         // here sweet list of hair dos     }      public override void viewdidload()     {         uicollectionviewflowlayout layout = new uicollectionviewflowlayout ()          {             headerreferencesize = new sizef(0, 0), // no header             footerreferencesize = new sizef(0, 0), // no footer             sectioninset = new uiedgeinsets(0, 0, 0, 0), // no section inset             itemsize = new sizef(uiscreen.mainscreen.bounds.width, 100f), // set each item full width of screen , 100 pixels tall             scrolldirection = uicollectionviewscrolldirection.vertical, // set collection scroll vertically             minimuminteritemspacing = 0, // no item spacing             minimumlinespacing = 0, // no line spacing         };          var thingcollectionviewcontroller = new uicollectionviewcontroller(layout);         var thingcollectionview = new uicollectionview(uiscreen.mainscreen.bounds.size);          thingcollectionviewcontroller.collectionview.frame = thingcollectionview.frame;         thingcollectionview = thingcollectionviewcontroller.collectionview;         thingcollectionview.delegate = new thingdelegateflowlayout(things);         thingcollectionview.backgroundcolor = uicolor.clear; // or whatever         thingcollectionview.backgroundview = new uiview ()          {             backgroundcolor = uicolor.clear // or whatever         };          view.addsubview (thingcollectionview);     } } 

i don't know how uitableview. i've stopped using table views, because more prefer uicollectionviews.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -