2016-08-16 5 views
0

私はCKEditorをUIWebView内のiOS 8.0に組み込むために数日間苦労しています。どんな助けもありがたい。iOS 8.0用CKEditor 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> 

答えて

0

があなたのWebView

[self.view addSubview:webView]; 
[webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]]; 
[webView stringByEvaluatingJavaScriptFromString:javascriptCode]; 
+0

私はそのコードを追加しましたが、結果は同じです。コンソールにエラーはありません。 – rleedev

0

でhtmlStringをロードした後、あなたのjavascriptCodeを評価してください私は私の問題への答えを見つけました。

代わりにWKWebViewを使用することに決めました。

以下は私のコードです。

-(void)adjustWebView { 

    // Load foundation HTML of webView 

    // Test loading website URL: 
    // [self webViewLoadURL:@"http://www.apple.com"]; 

    // Loading website File: 
    [self webViewLoadHTMLFile:@"defaultEditor"]; 

    self.webView.allowsBackForwardNavigationGestures = true; 

} 

-(void)webViewLoadURL:(NSString *)string { 

    NSURL *url = [NSURL URLWithString:string]; 
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]]; 

} 

-(void)webViewLoadHTMLFile:(NSString *)filename { 

    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"html"]; 
    NSString * stringHTML; 

    @try { 

     stringHTML = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; 
     [self.webView loadHTMLString:stringHTML baseURL:nil]; 

    } @catch (id exception) { 

     stringHTML = nil; 

    } 
} 
関連する問題