我有一個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