swift__UITableView 的数据源方法 和 代理方法
2016-01-20 17:14
381 查看
//MARK:- UITableView
的数据源方法 和
代理方法
//
返回行数
func tableView(tableView:
UITableView, numberOfRowsInSection section: Int) ->
Int
{
return
keyPointArray.count
}
// 每一行的内容显示
func tableView(tableView:
UITableView, cellForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCell
{
// cell的标识符,为了重复利用一个cell显示多行数据(复用)
let cellID =
"keyPointCell"
let myCell:UITableViewCell =
UITableViewCell(style:
UITableViewCellStyle.Default, reuseIdentifier: cellID)
myCell.textLabel?.text =
keyPointArray[indexPath.row]
myCell.accessoryType =
UITableViewCellAccessoryType.Checkmark
return myCell
}
// 是否允许打开编辑状态
func tableView(tableView:
UITableView, commitEditingStyle editingStyle:
UITableViewCellEditingStyle, forRowAtIndexPath indexPath:
NSIndexPath)
{
}
//
删除某行cell
// func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
// {
//
//
// }
//
允许滑动删除
func tableView(tableView:
UITableView, editingStyleForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCellEditingStyle {
return (UITableViewCellEditingStyle.Delete)
}
// 允许移动某行(排序)
func tableView(tableView:
UITableView, canMoveRowAtIndexPath indexPath:
NSIndexPath) -> Bool {
return
true
}
//
实现排序
func tableView(tableView:
UITableView, moveRowAtIndexPath sourceIndexPath:
NSIndexPath, toIndexPath destinationIndexPath:
NSIndexPath) {
}
//
点击某行
func tableView(tableView:
UITableView, didSelectRowAtIndexPath indexPath:
NSIndexPath) {
print("点击了第\(indexPath.row)行")
}
的数据源方法 和
代理方法
//
返回行数
func tableView(tableView:
UITableView, numberOfRowsInSection section: Int) ->
Int
{
return
keyPointArray.count
}
// 每一行的内容显示
func tableView(tableView:
UITableView, cellForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCell
{
// cell的标识符,为了重复利用一个cell显示多行数据(复用)
let cellID =
"keyPointCell"
let myCell:UITableViewCell =
UITableViewCell(style:
UITableViewCellStyle.Default, reuseIdentifier: cellID)
myCell.textLabel?.text =
keyPointArray[indexPath.row]
myCell.accessoryType =
UITableViewCellAccessoryType.Checkmark
return myCell
}
// 是否允许打开编辑状态
func tableView(tableView:
UITableView, commitEditingStyle editingStyle:
UITableViewCellEditingStyle, forRowAtIndexPath indexPath:
NSIndexPath)
{
}
//
删除某行cell
// func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
// {
//
//
// }
//
允许滑动删除
func tableView(tableView:
UITableView, editingStyleForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCellEditingStyle {
return (UITableViewCellEditingStyle.Delete)
}
// 允许移动某行(排序)
func tableView(tableView:
UITableView, canMoveRowAtIndexPath indexPath:
NSIndexPath) -> Bool {
return
true
}
//
实现排序
func tableView(tableView:
UITableView, moveRowAtIndexPath sourceIndexPath:
NSIndexPath, toIndexPath destinationIndexPath:
NSIndexPath) {
}
//
点击某行
func tableView(tableView:
UITableView, didSelectRowAtIndexPath indexPath:
NSIndexPath) {
print("点击了第\(indexPath.row)行")
}
相关文章推荐
- Swift 简单介绍 - 苹果最新的编程语言
- iOS开发--Swift 如何完成工程中Swift和OC的混编桥接(Cocoapods同样适用)
- Swift版快速排序
- Swift 2.0 字符串学习笔记(建议掌握OC字符串知识的翻阅)
- 秒学Swift开发语言
- Swift- 自定义导航栏背景、标题和返回按钮属性
- swift 函数
- 【Swift 2.1】为 UIView 添加点击事件和点击效果
- Swift 中的floor()函数 用途
- 集合 Swift 增删改查
- 《从零开始学Swift》学习笔记(Day 62)——Core Foundation框架之内存托管对象与非托管对象
- 《从零开始学Swift》学习笔记(Day 62)——Core Foundation框架之内存托管对象与非托管对象
- 理解Swift中Optional类型-有和无的哲学
- Swift语法基础入门四(构造函数, 懒加载)
- Swift语法基础入门三(函数, 闭包)
- 秒学Swift语言
- Swift语法基础入门二(数组, 字典, 字符串)
- Swift语法基础入门一(适合有C, OC开发人员)
- swift手记-2
- Swift利用闭包反向传值