我有一个UIViewController内,其中我把一个UIWebView的iOS - UIWebView中不显示HTML
然后我说这.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
会有人知道我做错了什么?我感觉我差点忘了一些一件小事:)
对不起,那一行应该在哪里?我不会注意到loadRequest - 你的意思是viewDidAppear中的最后一行 - 那是行不通的。 – GeekedOut
只需检查一下,您是否使用故事板创建了网页视图? – Alan
是的,我使用故事板创建了视图,但是我手动编写了代码,这可能是问题所在。 – GeekedOut