我一直在努力將CKEditor併入UIWebView中的iOS 8.0。任何幫助讚賞。CKEditor for iOS 8.0無法加載JavaScript文件
我有一個空的項目,並添加了這段代碼。
ViewController.m:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor grayColor];
[self loadWebViewFromFile];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)loadWebViewFromFile {
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 500)];
NSString *jsFile = @"ckeditor.js";
NSString *jsFilePath = [[NSBundle mainBundle] pathForResource:jsFile ofType:nil];
NSURL *jsURL = [NSURL fileURLWithPath:jsFilePath];
NSString *javascriptCode = [NSString stringWithContentsOfFile:jsURL.path encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:javascriptCode];
[self.view addSubview:webView];
[webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]];
}
@end
結果屏幕捕獲: Simulator for iPhone 6 - Deployment Target 9.0
新增的CKEditor來支持文件目錄。 Added CKEditor to Support Files
當我在Safari瀏覽器中加載它時,它很好。這就是我想要的WebView。
的index.html:
<!DOCTYPE html>
<!--
Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
-->
<html>
<head>
<meta charset="utf-8">
<title>CKEditor Sample</title>
<script src="ckeditor.js"></script>
<script src="./js/sample.js"></script>
</head>
<body id="main">
<main>
<div class="adjoined-bottom">
<div class="grid-container">
<div class="grid-width-100">
<div id="editor">
<h1>Hello world!</h1>
<p>I'm an instance of <a href="http://ckeditor.com">CKEditor</a>.</p>
</div>
</div>
</div>
</div>
</main>
<script>
initSample();
</script>
</body>
</html>
我已經添加了該代碼,但結果仍然相同。控制檯中沒有錯誤。 – rleedev