uitableview - Calculate table cell height according to the UIWebView content in iOS? -


i creating table view based application, when user tap on table row have set uiwebview displaying expandable uitableview having different html contents. it's working fine problem how set cell height according html contents, there lots of similar question in stackoverflow mine case different. know how calculate content height using uiwebview delegate methods, how can apply here?

here code :

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return [self.arrayhtmldescription count]; }  - (uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     uiwebview *webview;     static nsstring* cellidentifier = @"cell";      uitableviewcell* cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if (!cell)     {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:nil];         webview = [[uiwebview alloc] init];         webview.frame = cgrectmake(0, 0, cell.bounds.size.width, 500);     }      webview.userinteractionenabled = no;     [webview sizetofit];     webview.delegate = self;     webview.backgroundcolor = [uicolor clearcolor];     webview.opaque = no;     [webview loadhtmlstring: [[self.arrayhtmldescription objectatindex:indexpath.section] objectatindex:indexpath.row] baseurl: nil];      [cell.contentview addsubview:webview];      return cell; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return 1; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return 500; // need set height dynamically } 

code calculating height of uiwebview :

- (void)webviewdidfinishload:(uiwebview *)webview {     webview.scrollview.scrollenabled = no;     cgrect frame = webview.frame;     frame.size.height = 1;     webview.frame = frame;     cgsize fittingsize = [webview sizethatfits:cgsizezero];     frame.size = fittingsize;     webview.frame = frame;     nslog(@"webview height : %f", fittingsize.height); } 

please suggest me how pass fittingsize heightforrowatindexpath table view method. thanks!

keep nsmutablearray of height each cell in table , use value in delegate method :

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return [self.height array objectatindex:indexpath.row];  } 

when calculate height webview, update array , call reloadrowsatindexpaths method or reload entire tableview.

- (void)webviewdidfinishload:(uiwebview *)webview {     // caluclate height , update array of heights. [self.tableview reloaddata];   } 

edit: caluclate nsindexpath can use tag property of uiwebview shown below :

- (uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     // code create webview       webview.tag = indexpath.row;     [cell.contentview addsubview:webview];      return cell; } 

now after caluclating height can create indexpath using:

- (void)webviewdidfinishload:(uiwebview *)webview {         // caluclate height , update array of heights.    nsindexpath *indexpath = [nsindexpath indexpathforrow:webview.tag insection:0];     [tableview reloadrowsatindexpaths:[nsarray arraywithobject:indexpath]] withrowanimation:uitableviewrowanimationfade];        } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -