I have a webview in a uitableview cell. The problem is that the web view only takes up 75% of the uitableview cell
I am not sure how iOS decided the height of the web view, as I can’t seem to increase how much space it takes. I can increase the tableview cell’s height higher or lower, but the web view does not increase.
One thing I imagined I needed to do was somehow get the height of the web view itself based on how big the text is so that it can automatically scale the size of the tableview cell.
a) I’m not sure what function retrieves it
b) I think this would go in (void)webViewDidFinishLoad:(UIWebView *)webView method, but I can’t get the app to go into that function. I tried debugger and it seems not to go in there at all. (web view object is within its own controller)
#import "WebViewCell.h"
NSUInteger const WEB_VIEW_ROW_HEIGHT = 75;
@implementation WebViewCell
@synthesize webView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
and in the controller which actual populates the tableview cell with the web view:
WebViewCell *cell = [[ViewManager instance] loadWebViewCell:self.tableView cellID:eventDetailsValueCellID];
NSString *htmlText = [news valueForKey:propertyName];
[cell.webView loadHTMLString:htmlText baseURL:nil];
return cell;
I’m not sure where to put the (void)webViewDidFinishLoad:(UIWebView *)webView method with this setup. Does it go in the WebViewCell.m or the controller that calls WebViewCell.m
also,the root question is how can I make the web view scale to the size of the cell?
The
(void)webViewDidFinishLoad:(UIWebView *)webViewneeds to be implemented by the UIWebViewDelegate.Try adding
cell.webView.delegate = selfin the cellForRowAtIndexPath method and also adding the delegate protocol ‘UIWebViewDelegate’ to your controller’s header file.This should at least get your
(void)webViewDidFinishLoad:(UIWebView *)webViewcall to fire allowing you to do your height calculation after the web view has loaded.The calculation would probably look something like: