2012-10-25 95 views
1

我正在嘗試使用wysihtml5的簡單實現來執行富文本編輯(並直接存儲html以便能夠以標準格式保存格式)。iOS中的wysihtml5文本編輯器UIWebView

爲此,我已經實現wysihtml5這樣

<form> 
    <textarea id="textarea"></textarea> 
</form> 

<script src="./wysihtml5/parser_rules/simple.js"></script> 
<script src="./wysihtml5/dist/wysihtml5-0.3.0.js"></script> 
<script>  
    var editor = new wysihtml5.Editor("textarea", { 
    parserRules: wysihtml5ParserRules, 
    useLineBreaks: false 
    }); 
</script> 

爲了能夠操縱它在iOS中,我使用stringByEvaluatingJavaScriptFromString作爲

- (void) setText:(NSString *)text 
{        
    [self.webView 
     stringByEvaluatingJavaScriptFromString:[NSString 
           stringWithFormat:@"editor.setValue(%@)", text]]; 
} 
- (NSString *)getText 
{ 
    NSString *text = [self.webView 
        stringByEvaluatingJavaScriptFromString:@"editor.getValue()"]; 
    return text; 
} 

然而,無論是套作品,也不是GET(總是返回一個空字符串)。 任何線索?

回答

0
- (void)insertHTMLContent:(NSString *)HTMLBody 
{ 
    if (HTMLBody) { 
     NSString *query = [NSString stringWithFormat:@"editor.composer.commands.exec('insertHTML', '%@')", HTMLBody]; 
     [self stringByEvaluatingJavaScriptFromString:query]; 
    } 
} 

- (NSString *)getContentHtml { 
    return [self stringByEvaluatingJavaScriptFromString: @"editor.getValue()"]; 
}