Ios 无法在UIWebView中加载html文件

Ios 无法在UIWebView中加载html文件,ios,objective-c,uiwebview,Ios,Objective C,Uiwebview,我有一个具有UIWebView的视图控制器。我想在UIWebView中加载一个html文件。 我将我的html文件保存在支持文件(由Xcode生成)->Resources->html下。 此外,我还创建了html文件并拖放到html文件夹中。 我的代码: -(void)viewDidLoad { [super viewDidLoad]; NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"contact"

我有一个具有UIWebView的视图控制器。我想在UIWebView中加载一个html文件。 我将我的html文件保存在支持文件(由Xcode生成)->Resources->html下。 此外,我还创建了html文件并拖放到html文件夹中。 我的代码:

-(void)viewDidLoad
{
     [super viewDidLoad];
     NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"contact" 
                              ofType:@"html" inDirectory:@"Resources/html"] ;
     NSURL *url = [NSURL fileURLWithPath:htmlFile    ];
     NSURLRequest *request = [NSURLRequest requestWithURL:url];
     [_webView loadRequest:request];
     _webView.delegate=(id)self;
}
我错过了什么。看起来很傻,但运气不好。。
请提供帮助。

用此方法替换您的视图加载方法。我查过了。这对我有用。请注意,您的html文件应如图所示放置。(根据您的需要)

-(void)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
UIWebView*webView=[[UIWebView alloc]init];
frame=CGRectMake(0,0320568);
NSString*htmlFile=[[NSBundle mainBundle]pathForResource:@“contact”类型:@“html”inDirectory:nil];
NSString*htmlString=[NSString STRINGWITHCONTENTSOFILE:htmlFile编码:NSUTF8STRING编码错误:nil];
//附加javascript
//NSString*script=@“警报(\“这是一个警报!!\”)”;
//htmlString=[htmlString stringByAppendingString:script];
webView.delegate=self;
[webView加载htmlString:htmlString基URL:nil];
[self.view addSubview:webView];
}

请参考此链接,它是随机工作的…我有表单元格,对于index=0,它工作,但对于其他单元格索引不工作。您可以从这里获得帮助
 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

        UIWebView *webView=[[UIWebView alloc]init];
        webView.frame=CGRectMake(0, 0, 320, 568);
        NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"contact" ofType:@"html" inDirectory:nil];
        NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
        //Append javascript
        //NSString *script = @"<script>alert(\"This is an alert!!\");</script>";
        //htmlString = [htmlString stringByAppendingString:script];
        webView.delegate = self;
        [webView loadHTMLString:htmlString baseURL:nil];
        [self.view addSubview:webView];
}