I have a simple nib with few buttons and UIWebView
on which I want to display some HTML. I want to change the height in UIWebView
depending on HTML content. But I can't.
My nib look like this: My nib
My mainViewController.h
:
#import <UIKit/UIKit.h>
@interface ibecViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webV;
@end
I've used sizeToFit
, but it doesn't work. My mainViewController.m
:
#import "ibecViewController.h"
@interface ibecViewController ()
@end
@implementation ibecViewController
@synthesize webV;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myHTML = @"<html><body><h1>Hello, world!</h1><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p><p>Hello, world</p></body></html>";
[webV loadHTMLString:myHTML baseURL:nil];
[webV sizeToFit];
}
- (void)viewDidUnload
{
[self setWebV:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"123");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"456");
}
@end
My second question: Why don't the methods webViewDidStartLoad
and webViewDidFinishLoad
work? Despite I have writen that my controller conforms to UIWebViewDelegate
. I'm new in iOS.
The height of the WebView doesn't change. And my application looks like this:
My app