文本将会实现把数据存储到plist文件里。然后在程序中进行读取。在TableView控件中依据不同的类别显示Section。

有关TableView 的其它实现,请參考《iOS项目开发实战——学会使用TableView列表控件(一)》《iOS项目开发实战——学会使用TableView列表控件(二)》《iOS项目开发实战——学会使用TableView列表控件(三)了解Section》。

(1)新建一个Property List文件,这个也就是plist文件。我取名为data.plist。输入内容例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">.

(2)代码中实现例如以下:

import UIKit

class ViewController: UIViewController ,UITableViewDataSource{

  var data:NSDictionary!

  override func viewDidLoad() {
super.viewDidLoad() data = NSDictionary(contentsOfURL: NSBundle.mainBundle().URLForResource("data", withExtension: "plist")!) } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell var title = cell.viewWithTag(101) as! UILabel
title.text = (data.allValues[indexPath.section] as! NSArray).objectAtIndex(indexPath.row) as? String return cell } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return (data.allValues[section] as! NSArray).count
} func numberOfSectionsInTableView(tableView: UITableView) -> Int { return data.count
} func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return data.allKeys[section] as? String
} }

(3)最后的实现效果例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">。

github主页:https://github.com/chenyufeng1991  。

欢迎大家訪问。

最新文章

  1. 【面试题】D
  2. ZOJ 3696 Alien's Organ
  3. STM32F105解密STM32F105VB芯片解密STM32F105R8单片机破解多少钱?
  4. Python 对目录中的文件进行批量转码(GBK>UTF8)
  5. JUnit3的作用
  6. PL/SQL Developer 9.x 注册码
  7. Dictionary和IDictionary
  8. HBase(八): 表结构设计优化
  9. Parallel WebDriver executions using TestNG
  10. 阿里云服务器(Win 2008 R2 Standard)安装MSSM 2008 R2之1033和2052问题
  11. linux下mysql配置文件my.cnf详解
  12. Hadoop 学习笔记(一) HDFS API
  13. Visual Studio 2013 上使用 Github
  14. 数论+dp Codeforces Beta Round #2 B
  15. rgba()和opacity的使用
  16. 从LINQ开始之LINQ to Objects(下)
  17. 对于php内存释放问题
  18. Linux IO模型(同步异步阻塞非阻塞等)的几篇好文章
  19. 使用redis作为Return存储方式
  20. python中print和input的底层实现

热门文章

  1. LockSupport的park和unpark的基本使用,以及对线程中断的响应性
  2. Java之旅--定时任务(Timer、Quartz、Spring、LinuxCron)
  3. yolo源码解析(三)
  4. Lp空间
  5. Chapter 6 -- Caches
  6. 【转】QT中QDataStream中浮点数输出问题
  7. Server 2008 R2大改造变成梦幻Win7系统
  8. CListCtrl 之右键菜单
  9. 大数据开发实战:Stream SQL实时开发一
  10. (转载)Java8新的日期API LocalDate, LocalTime