MGTemplateEngine 模版引擎简单使用以及MGTemplateEngine导入xcode6.1报错修改

MGTemplateEngine 模版引擎

一、  MGTemplateEngine比较象 PHP 中的 Smarty 模版引擎,是一个轻量级的引擎,简单好用。只要设置很多不同的HMTL模版,就能轻松的实现一个View多种内容格式的显示,对于不熟悉HTML或者减轻工作量而言,把这些工作让设计分担一下还是很好的,也比较容易实现设计想要的效果。

像网易、粉笔网都是用的该库。

首先,看看模版的代码

[html] view
plain
copy

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link href="./detail.css" rel="stylesheet">
  8. </head>
  9. <body>
  10. <div id=‘container‘ name="container">
  11. <div class="title">{{ title }}</div>
  12. <div class="date">{{ date }}</div>
  13. <div class="content">{{ content }}</div>
  14. </div>
  15. </body>
  16. </html>

Objective-C代码 - 下面的创建代码MGTemplateEngine都是从官方的例子中参考下来的,已经有很详细的说明

[objc] view
plain
copy

  1. // Set up template engine with your chosen matcher.
  2. MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
  3. //[engine setDelegate:self];
  4. [engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
  5. // 这里就是设置,或者里边塞变量的地方。其实也可以设置一个数组,这样模板的灵活也会更强。这里我就不演示了官方有例子
  6. [engine setObject:self.detailData[@"title"] forKey:@"title"];
  7. [engine setObject:self.detailData[@"content"] forKey:@"content"];
  8. // MGTemplateEngine/Detail/detail.html
  9. // MGTemplateEngine/Detail/detail.css
  10. NSString *templatePath = [[NSBundle mainBundle] pathForResource:@"detail" ofType:@"html"];
  11. // Process the template and display the results.
  12. NSString *html = [engine processTemplateInFileAtPath:templatePath withVariables:nil];
  13. // 获得HTML
  14. self.htmlWebView = [[UIWebView alloc] initWithFrame:CGRectMake(8, 5, 304, 320)];
  15. self.htmlWebView.delegate = self;
  16. self.htmlWebView.userInteractionEnabled = NO;
  17. // 你就能加载到HTML里面的.css文件
  18. NSString *baseURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Detail"];
  19. [self.htmlWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:baseURL]];
  20. [self.detailView addSubview:self.htmlWebView];

以上的都是 MGTemplateEngine 很基本的使用,将来也会大派用场的。对于内容页的显示,没有比HTML来的更方便直接,通过切换模版和简单的参数设置,多个不同类型的栏目也可以使用同一个详细页,很大程度上减轻工作理和易于维护。

二、在苹果公司不断的更新Xcode很多以前的库都被省略掉,所以以前的第三方导入到Xcode6.1 难免不会出现问题。同理今天我试了下导MGTemplateEngine,结果报了如下错误:

一番苦解后,原来是类中缺少<Foundation/Foundation.h>架包,import后问题解决。

时间: 2024-08-12 19:20:04

MGTemplateEngine 模版引擎简单使用以及MGTemplateEngine导入xcode6.1报错修改的相关文章

MGTemplateEngine 模版引擎简单使用(转)

原文:http://blog.csdn.net/crazy_srufboy/article/details/21748995 要实现的效果 首先上图中间的 标题至内容 都是使用UIWebView显示,评论是UITableView可以往下拖加载更多评论,也可以增加评论同删除评论. 动机 评细页中使用 UIWebView 会使显示内容更加的灵活和简单,当然你也许可以网上找UITextView的扩展同样也行,但我感觉HTML更符合我的需求.在多年的PHP开发中我们知道,其实详细页都是大同小异,主要是显

MGTemplateEngine 模版发动机简单使用

https://github.com/nxtbgthng/MGTemplateEngine MGTemplateEngine 模版引擎 MGTemplateEngine比較象 PHP 中的 Smarty 模版引擎.是一个轻量级的引擎,简单好用.仅仅要设置非常多不同的HMTL模版.就能轻松的实现一个View多种内容格式的显示,对于不熟悉HTML或者减轻工作量而言,把这些工作让设计分担一下还是非常好的,也比較easy实现设计想要的效果. 首先,看看模版的代码 <!DOCTYPE html> <

简单记录一次REDO文件损坏报错 ORA-00333重做日志读取块出错

一.故障描述 首先是实例恢复需要用到的REDO文件损坏 二.解决方法 1.对于非当前REDO或者当前REDO但是无活动事务使用以下CLEAR命令: 用CLEAR命令重建该日志文件SQL>alter database clear logfile group 3: 如果是该日志组还没有归档,则需要用SQL>alter database clear unarchived logfile group 3: 因为是当前实例恢复需要用的REDO,且未归档,使用是CLEAR命令不行的. 2.没备份,有备份可

eclipse 导入项目js报错问题

eclipse 导入项目js报错问题 eclipse 导入项目后会出现项目中的js文件报错(红叉),如下图所示,有时候报错的文件很多,需要集中处理. 解决办法:右键项目名称>Properties>JavaScript>Include Path,在右侧选择"Source"选项卡, 然后选择项目中的"Excluded"分支,在右侧点击"Edit",如下图所示: 在弹出的"Inclusion and Exclusion Pa

关于RN中导入第三方图片库报错:Unrecognized font family &#39;FontAwesome&#39;

废话不多说,上解决方案: 1.找到Fonts文件,把它拖到Images.xcassets目录下,下面是截图- 2.设置plist文件,别犹豫,手动修改 3clean-build-run,你会发现问题消失了,因为修改了xcode里面的东西,所以一定要重启项目. 关于RN中导入第三方图片库报错:Unrecognized font family 'FontAwesome'

PyCharm导入tensorflow包报错的问题

[注]PyCharm导入tensorflow包报错的问题 若是你也遇到这个问题,说明你也没有理解tensorflow到底在哪里. 当安装了anaconda3.6后,在PyCharm中设置interpreter,这个解释器决定了你在PyCharm环境中写的代码采用什么方式去执行. 若是你的设置是anaconda下的python.exe.就会发现在PyCharm中写入import tensorflow as tf 时,就会报错,提示没有tensorflow模块,这是因为anaconda文件下的pyt

AndroidStudio导入Eclipse项目报错Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject

AndroidStudio导入Eclipse项目报错 Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject 错误原因: Gradle插件版本不一致导致,问题多出现在:eclipse项目转studio 解决步骤: https://blog.csdn.net/qq_21397217/article/details/65630730 原文地址:https://www

编写简单的shell脚本 - for循环 - 解决报错 Syntax error: Bad for loop variable

为了编写批量导入数据的程序,故而学习编写shell脚本!现学现用! ============================================ 1.第一个简单的for循环 #!/bin/bashfor i in 1 2 3 4;do echo $i;done 2.测试for的自增长的循环: #!/bin/bashfor ((i=1; i<=5; i++))do echo $i;done 如果会报错,没有则跳过: Syntax error: Bad for loop variable

myeclipse_导入js文件报错

myeclipse导入外部的js文件时.myeclipse自动报错.外部导入的官方js包应该是没有错的. 可以选中报错的js文件-->右键-->myeclipse-->exclude from  validation. 还报错的话就继续操作不过最后一步选择Run Validation eclipse下面Project Properties > JavaScript > Include Path > Source > 选中Exclude > 点击edit按钮