开发者

HTML and Cocoa Objects, will they dance together?

Hello fellow coders & codetts

I was wondering, if I needed to create a rich text formatted document using html and css, which will be used inside a UIWebView, could I then insert cocoa calls inside HTML tags? I do this in ruby, and many other langs do this as well, but I do not know if possible on the iphone.

My main goal is to display a report that will pull data from coreData entities, format it to look pretty, and then create a PDF for the user to email or print.

The only reason I am using HTML is that is what someone here @ StackOverflow mentioned that was the best practice for the iphone. But I would really like to be able to just create a PDF without the HTML and UIWebV开发者_如何学JAVAIew, so If you know how this can be done, by all means do tell, the world wants to know.

thank u for your precious time


No, you can't (easily) access your Cocoa objects and classes from HTML/JavaScript. You can, however use Cocoa to call JavaScript methods on the loaded webpage. You can use these JavaScript methods to pass data from Cocoa to the web page, and in those JavaScript methods, you can then change the content of the webpage. That would look something like this:

[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doSomethingWithString('%@');", stringToPass]];

And on the JavaScript side:

function doSomethingWithString(passedString) {
  // show stuff in webpage
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜