0

How can we set a dynamic height of UITableViewCell which contents UIWebView. UIWebView contents dynamic data which is not fix. so I want to set a height of row dynamic. but problem is that, UITableView delegate method are call before a UIWebView's delegate. so how can I handle this??

Sarat Patel
  • 856
  • 13
  • 32

2 Answers2

2

reload your data in web view delegate

 -(void)webViewDidFinishLoad:(WebView *)webView{
    [tableview reloadata]; 
    }
  • Wrong dear, because this will goes into infinity loop. because `UITableView` contains `UIWebView` after reload call. `cellForRowAtIndexPath` again calls `UIWebView`'s delegate method..... – Sarat Patel Dec 18 '14 at 13:02
  • Then you can store height of webView in variable and set that value to height of each cell after reloading... – Mrugesh Tank Dec 18 '14 at 13:09
2

Your question is unclear, you're saying webview's content is dynamic, however there should be some fixed size height of the webview. You can manage height of webview, in - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath datasource method.

I think, you should replace webview with UILabel. And calculate text height and set height based on that.

Reference, Dynamic UITableView Cell Height Based on Contents

Community
  • 1
  • 1
Hemang
  • 26,840
  • 19
  • 119
  • 186
  • 1
    How can you recommend using a `UILabel` when you do not know what OP is using the `UIWebView` for? – mbogh Dec 18 '14 at 13:05
  • I know that, but `- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath` is called before the `cellForRowAtIndexPath` so how can I calculate the contents of `webView` which is inside the `tableViewCell`.I am sending URL's from XML which is coming from server side and it is my actual problem. I am unable to handle this. now I am going to refer your links @Hemang...thanks – Sarat Patel Dec 18 '14 at 13:08
  • IMHO, `UIWebView` is use to show HTML content (we can call web pages). Thus, if user need to show some text content inside a webview, he may use a label. @mbogh – Hemang Dec 18 '14 at 13:08
  • @Sarat_Patel, if possible, please let us know, what content you're showing in webview so that we can give you better answer for this. – Hemang Dec 18 '14 at 13:09
  • @Hemang I cant show that, but its just like a link which contains a **Information (theory)** , not fix it may be it contains 100 words or 100 lines. – Sarat Patel Dec 18 '14 at 13:17
  • @Sarat_Patel, This is not reasonable way for you, your code will become tricky and complex. If possible find an alternative for this. Get direct text from the API (doesn't matter if its HTML texts). You can show it in `UILabel` (attributed). – Hemang Dec 18 '14 at 13:35