I’m so close on this one. Basically what I’m trying to do is return the height of a cell for my UIWebView. I’ve got the correct height printing out on my NSLOG. The problem now is that I need to make a variable out of that height. So far no luck. Here is what I have right now.
- (void)webViewDidFinishLoad:(UIWebView *)webView {
_descriptionWebView.frame = CGRectMake(_descriptionWebView.frame.origin.x, _descriptionWebView.frame.origin.y, _descriptionWebView.frame.size.width, 1);
CGSize fittingSize = [_descriptionWebView sizeThatFits:CGSizeZero];
_descriptionWebView.frame = CGRectMake(_descriptionWebView.frame.origin.x, _descriptionWebView.frame.origin.y, _descriptionWebView.frame.size.width, fittingSize.height);
NSLog(@" Fitting Size is : %f", fittingSize.height);
}
It prints out the perfect size for each article that will display in the UIWebView (inside a UITableViewCell). My main problem is how do I return that height in –
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == SectionHeaderTitle) {
// Regular
return 54;
} else {
return 612;
}
}
I’ve tried to make an instance variable out of fittingSize, using NSNumber, NSInteger, CGFloat, CGRect, CGSize…and basically I get “incompatible result type”.
Ultimately what I want is to return fittingSize.height;
Any help on getting there? Thank you very much in advance. Hopefully I didn’t leave anything out!
CGSize.height is a CGFloat. Where are you getting the “incompatible result type”?
You should be able to declare a CGFLoat variable
CGFloat fittingHeight;in your interface, then assign it in your -webViewDidFinishLoad:Then use it in
-tableView:heightForRowAtIndexPath:.