相关疑难解决方法(0)

如何将本地html文件加载到UIWebView中

我正在尝试将html文件加载到我的UIWebView中,但它不起作用.这是舞台:我的项目中有一个名为html_files的文件夹.然后我在界面构建器中创建了一个webView,并在viewController中为它分配了一个插座.这是我用来附加html文件的代码:

-(void)viewDidLoad
{
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html" inDirectory:@"html_files"];
    NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
    [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
    [super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,UIWebView是空白的.我很感激一些帮助.

iphone cocoa-touch objective-c uiwebview ios

165
推荐指数
7
解决办法
19万
查看次数

读取文档目录中的.txt文件

如何读取文档目录中的.txt文件?你能告诉我代码吗?

ios nsdocumentdirectory

18
推荐指数
1
解决办法
1万
查看次数

OSX Swift webview加载本地文件

我知道这已经被问了很多次,我已阅读相当 一个 问题 ,并用Google搜索,但没有成功,到目前为止天。

我只想在桌面应用程序中加载一个本地 html 文件,事实是这个项目我需要一个 JS 库,其中大部分已经作为网页完成(css、js 和 html,不需要服务器端处理)。我不想强制应用程序从互联网服务器加载网页,以免强迫用户连接互联网。不用说,我在 Swift 和苹果开发方面完全没有经验。

现在这是我遇到的问题: 在此处输入图片说明 关于参数的 ide 抱怨,我似乎无法理解它们。

作为参考,这里是我最新代码的片段:

class AppDelegate: NSObject, NSApplicationDelegate
{
    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var webView: WebView!
    typealias NSSize = CGSize

    func applicationDidFinishLaunching(aNotification: NSNotification?)
    {
        self.window.title = "Chess Study Room"

        var try1 = "main.html";
        println(try1);

        var try2 = NSURL(string: try1)!;
        println(try2);

        var try3 =
        NSBundle.URLForResource("main", withExtension: "html", subdirectory: "web", inBundleWithURL: try2);
        println(try3);

        var try4 = NSBundle.pathForResource("main", ofType: "html", inDirectory: "web");
        println(try4);

        var …
Run Code Online (Sandbox Code Playgroud)

macos local webview swift

5
推荐指数
1
解决办法
7756
查看次数