swift UITableView(五)
来源:互联网 发布:office办公软件 编辑:程序博客网 时间:2024/06/07 19:39
前几节 我们主要讲了简单的创建一个tableView 添加一些数据,稍微做了一些修饰。
接下来我们看一个比较常用的功能 多分区tableView
首先接着之前的源代码来修改一下 上节源代码的数据源(代码见上节文章尾部)
- _dataArray=[[String]]()
- _dataSubtitleArray=[String]()
- for i in 1...10
- {
- var arr=[String]()
- for j in 1...3{
- arr.append("第\(i)分区,第\(j)行")
- }
- _dataArray.append(arr)
- }
添加一个UITableViewDelegate的代理方法
- //设置分区个数
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return _dataArray.count
- }
- //设置每个分区下需要展示的行数
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return _dataArray![section].count
- }
运行效果如下:
我们能看到 数据已经按照分区现实出来了
但是,感觉好像还和之前的一样,一行一行现实的分区和没分区一样的效果。
下来我们添加一下分区头,这样效果就会更加明显
只需要添加一个代理方法即可
- //设置分区个数
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return _dataArray.count
- }
运行效果如下:
既然后分区头,那么也应该有分区尾。
我们实现一下分区尾看看效果
- //设置分区尾标题
- func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
- return "第\(section)分区尾部"
- }
看下效果
0 0
- swift UITableView(五)
- Swift UITableView相关功能(五)多分区tableView
- swift UITableView(一)
- swift UITableView(二)
- swift UITableView(三)
- swift UITableView(四)
- swift UITableView(六)
- swift UITableView(七)
- swift UITableView(八)
- Swift ☞ UITableView(一)
- Swift基础(十六)UITableView
- swift uitableview
- swift UItableView
- UITableView --Swift
- Swift 笔记(五)
- Swift数据类型(五)
- swift之自定义表格控件(UITableView)
- UITableView 应用(五)UITableView样式的自定义
- jquery(zepto) when then 使用
- LeetCode Majority Element
- Epoll
- ArcGIS教程:影响路径距离(水平系数)(二)
- swift UITableView(四)
- swift UITableView(五)
- Linux 格式化分区 报错Could not stat --- No such file or directory 和 partprobe 命令
- uva11997 K Smallest Sums
- 严重: Error configuring application listener of class org.springframework.web.context.ContextLoader
- UIButton的imageEdgeInsets和titleEdgeInsets属性 —— HERO博客
- cf(数学思维题)
- HOW TO: Find the Problem Exception Stack When You Receive an UnhandledExceptionFilter Call in the St
- swift UITableView(六)
- Android小记:Android入门教程