开发者

how do I render an NSObject in local HTML template in iOS [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

I have a local html file I would like to use as a template to print some different NSObjects, is there a way to r开发者_高级运维ender this without having to do a bunch of stringByReplacingOccuranceOfString methods?

Looking for something I would do in MVC on a web site:

HTML Template:

    <html>
    <head>
    </head>
    <body>
    <h1>Manufacturer</h1>
     <p>
     ##Manufacturer.ManufacturerName##
     </p>
    </body>
    </html>

And would call some function passing in the Manufacturer object and get an NSString back of that template with the object property values substituted in place of my placeholder values.


You can do something like this:

NSString *html = [NSString stringWithFormat:@"<html>
<head>
</head>
<body>
<h1>Manufacturer</h1>
 <p>
%@
 </p>
</body>
</html>",  Manufacturer.ManufaacturerName];  
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"some random page"]];  //I'm not entirely sure what the baseURL is used for


Look at the always-brilliant Matt Gemmell's MGTemplateEngine.


https://github.com/groue/GRMustache is a nice alternative to Matt Gemmel's MGTemplateEngine that works on both iOS and MacOS out of the box, and has copious documentation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜