Reputation: 17185
I have a UIViewController inside of which I put a UIWebView
Then I added this to the .h file:
#import <UIKit/UIKit.h>
@interface BuildBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;
@end
and have this as the .m file
#import "BuildBusinessController.h"
@interface BuildBusinessController ()
@end
@implementation BuildBusinessController
@synthesize theWebView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
theWebView.delegate = self;
}
- (void)viewDidUnload
{
[self setTheWebView:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewDidAppear:(BOOL)animated
{
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"build_business" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest *rq = [NSURLRequest requestWithURL:url];
[theWebView loadRequest:rq];
}
@end
But the build_business.html file is not rendering inside the view, and also I get a warning on this line: theWebView.delegate = self; which says:
Assigning to id 'UIWebViewDelegate from incompatible type BuildBusinessController *const_string
Would anyone know what I am doing wrong here? It feels I am forgetting some one small thing :)
Upvotes: 0
Views: 2031
Reputation: 260
In addition to F.X. answer, I think you forgot to add this in viewDidAppear (after loadRequest):
[self.view addSubview:theWebView];
Update: The issue is caused by OP failing to configure delegate for UIWebView in Storyboard. The code snippet provided here will only work if you are coding it manually. Otherwise, as stated by @F.X. in the comments below, Storyboard will implement this automatically.
Upvotes: 1
Reputation: 7317
You're just forgetting UIWebViewDelegate
on your class definition :
#import <UIKit/UIKit.h>
@interface BuildBusinessController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;
@end
Upvotes: 1