嗨我想從我的項目中加載html和.js文件。這些是下面的步驟,我通過框架加載HTML文件,但我無法擊中HTML文件。從框架加載html文件可能嗎?
接下來的步驟。
創建一個框架,其中webview作爲子視圖。
創建Resource.bundle並添加了我的所有html,.js文件和圖像。
當我將這個框架添加到我的項目中,並嘗試從包中訪問圖像我無法。 當我嘗試擊中html文件時,我無法在我的webview中放置html文件。
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Resource" ofType:@"bundle"];
NSString *htmlFile = [[NSBundle bundleWithPath:bundlePath] pathForResource:@"simple" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSURL *url=[[NSBundle mainBundle] bundleURL];
[webview loadHTMLString:htmlString baseURL:url];
[self addSubview:webview];
有誰能告訴我爲什麼這不會工作,這是正確的方法?
嘗試此[web視圖的loadRequest:的NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[一個NSBundle mainBundle] pathForResource:@ 「測試」 ofType:@ 「HTML」] isDirectory:NO]]]; – Spynet
您是否確認資源確實在捆綁中?檢查您的構建產品並使用Finder打開該包。 –
@Joris Kluivers是資源在捆綁... – Abhilash