【问题标题】:Show Html Page in my iPhone view在我的 iPhone 视图中显示 Html 页面
【发布时间】:2014-02-27 04:40:29
【问题描述】:

我试图在我的应用程序中显示一个html 页面,但它没有显示在视图中:

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"abt.html"];
NSURLRequest *documentsRequest = [NSURLRequest requestWithURL:
                                  [NSURL fileURLWithPath:path]] ;

[_webview loadRequest:documentsRequest] ;

我点击了这个链接:iOS - display content from an html resource file or remote webpage in a webview

马特·吉布森

请告诉我如何显示。

谢谢

【问题讨论】:

  • 这里可能有很多问题...webView 可能没有正确初始化,“Path”变量可能为空..您需要提供更多信息。

标签: ios iphone ios6 ios7


【解决方案1】:

正如您所说,您的 html 页面在应用程序中,所以试试这个,我已经使用它并且它工作正常。

 NSString *htmlFile=[[NSBundle mainBundle] pathForResource:@"abt" ofType:@"html"];
 NSString *htmlString=[NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:Nil];
 [_webview loadHTMLString:htmlString baseURL:nil];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多