我正在尝试将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是空白的.我很感激一些帮助.
我知道这已经被问了很多次,我已阅读相当 一个 小 问题 ,并用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) ios ×2
cocoa-touch ×1
iphone ×1
local ×1
macos ×1
objective-c ×1
swift ×1
uiwebview ×1
webview ×1