iOS项目开发实战——学会使用TableView列表控件(三)了解Section
2015-08-23 20:20
741 查看
在列表控件TableView中,Section可以用来分隔不同功能的Cell,如下的iPhone设置界面就是用了Section。现在我们要自己来实现一下带Section的TableView。
。
(1)关于如何设置界面以及拖拉控件,请参考我的前面2篇博客《iOS项目开发实战——学会使用TableView列表控件(一)》《iOS项目开发实战——学会使用TableView列表控件(二)》。
(2)在代码中实现如下:
(3)运行程序,实现效果如下:
.
github主页:https://github.com/chenyufeng1991 。欢迎大家访问!
。
(1)关于如何设置界面以及拖拉控件,请参考我的前面2篇博客《iOS项目开发实战——学会使用TableView列表控件(一)》《iOS项目开发实战——学会使用TableView列表控件(二)》。
(2)在代码中实现如下:
import UIKit class ViewController: UIViewController ,UITableViewDataSource{ var array = ["Hello","iOS","Swift"] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell var title = cell.viewWithTag(101) as! UILabel title.text = array[indexPath.row] return cell } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 2 //设置有2个Section; } func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { var str:String! if(section == 0){ str = "页脚:第一个section" }else{ str = "页脚:第二个section" } return str } func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { var str:String! if(section == 0){ str = "页眉:第一个section" }else{ str = "页眉:第二个section" } return str } }
(3)运行程序,实现效果如下:
.
github主页:https://github.com/chenyufeng1991 。欢迎大家访问!
相关文章推荐
- ios线程-NSoperatiion
- 基于OpenCV的iOS开发笔记(1)
- iOS项目开发实战——学会使用TableView列表控件(二)
- IOS-NSDictionary
- IOS-音乐播放器
- iOS prototype Cells
- iOS-项目的目录结构能看出你的开发经验
- iOS 宏(define)与常量(const)的正确使用
- iOS 调出storyboard里面起始Controller的箭头
- iOS几种传值方法的总结
- ios图文混排简单演示
- iOS项目开发实战——学会使用TableView列表控件(一)
- ios沙盒的使用
- 教你搞定IOS远程消息推送APNS
- iOS NSURLSession 下载
- ios 抓包工具 ios青花瓷charles
- iOS storyboard push到下一个界面后怎么再从下一个界面返回上一个界面
- iOS 自定义动画 push/pop动画
- iOS ImagePickerController 入门
- ios键盘不遮挡输入框