博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS项目开发实战——学会使用TableView列表控件(四)plist读取与Section显示
阅读量:7240 次
发布时间:2019-06-29

本文共 1297 字,大约阅读时间需要 4 分钟。

       文本将会实现把数据存储到plist文件里。然后在程序中进行读取,在TableView控件中依据不同的类别显示Section。有关TableView 的其它实现,请參考《》《》《》。

(1)新建一个Property List文件。这个也就是plist文件。我取名为data.plist。

输入内容例如以下:

.

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

import UIKitclass 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)最后的实现效果例如以下:

github主页:  。欢迎大家訪问!

转载于:https://www.cnblogs.com/gavanwanggw/p/6911588.html

你可能感兴趣的文章
微信公众开发接入服务器的接口配置信息
查看>>
deployment与Web应用程序部署
查看>>
详解iOS多图下载的缓存机制
查看>>
关于CAE的那点儿破事儿
查看>>
prometheus + grafana安装部署(centos6.8)
查看>>
排序算法之快速排序
查看>>
日志框架logj的使用
查看>>
架构师必看-架构之美第14章-两个系统的故事:现代软件神话(一)
查看>>
struts2从2.2.3升级到2.3.15.1步骤
查看>>
你所不了解的静态路由特点及配置
查看>>
37、pendingIntent 点击通知栏进入页面
查看>>
TCP为何采用三次握手来建立连接,若采用二次握手可以吗?
查看>>
Jfreet 自动删除生成的图片
查看>>
snmp
查看>>
java笔记----java新建生成用户定义注释
查看>>
批量删除记录时如何实现全选【总结】
查看>>
Thread’s start method and run method
查看>>
使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【二】——使用Repository模式构建数据库访问层...
查看>>
CDN发展史
查看>>
Atitit.研发团队的管理原则---立长不立贤与按资排辈原则
查看>>