在 UIWebView 中找到一个 html 文件 [英] Locate a html file in UIWebView

查看:22
本文介绍了在 UIWebView 中找到一个 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NotificationVC,其中包含索引 0 到 9 的 10 个单元格的表格视图.单击每个单元格 NotificationWebVC 应该打开它具有加载差异的 UIWebView.html 取决于在 NotificationVC 中选择的单元格.现在我的代码只适用于 index=0 ,但不适用于其他索引,看起来有点奇怪.

I have a NotificationVC containing table view having 10 cells index 0 to 9. on click of each cell NotificationWebVC should open up that has a UIWebView that loads diff. html depending upon which cell is selected in NotificationVC. Right now my code works only for index=0 , but not for other indexes , seems bit weird.

NotificationWebVC
- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:_resourceName ofType:@"html" inDirectory:nil] ;

    NSURL *url = [NSURL fileURLWithPath:htmlFile];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
    _webView.delegate=(id)self;


}

请推荐._resourceName 是具有 html 文件名称的属性.

Please suggest. _resourceName is a property having the name of html file.

推荐答案

// docfileName should be your file name call this method in tableview delegate didSelectrow

-(void)loadLocaldataonWebview :(NSString *)docfileName 
{
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:docfileName ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[documentsWebView loadHTMLString:htmlString baseURL:nil];
}

然后在viewDidload中添加如下代码

then in viewDidload add the following code

-(void)viewDidLoad{
documentsWebView=[[UIWebView alloc]init];
documentsWebView.delegate=self;
documentsWebView.frame=CGRectMake(0, yAxis, kWidth, 616);
documentsWebView.backgroundColor=[UIColor clearColor];
[self.view addSubview:documentsWebView];

}

这篇关于在 UIWebView 中找到一个 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆