我有一个 UIViewController 里面我放了一个 UIWebView
然后我将它添加到 .h 文件中:
#import <UIKit/UIKit.h>
@interface BuildBusinessController : UIViewController
@property (weak, nonatomic) IBOutlet UIWebView *theWebView;
@end
并将其作为 .m 文件
#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
但是 build_business.html 文件没有在视图内呈现,而且我在这一行收到警告:theWebView.delegate = self; 其中说:
从不兼容的类型 BuildBusinessController *const_string 分配给 id 'UIWebViewDelegate
有人知道我在这里做错了什么吗?感觉我忘记了一件小事:)