UITableView常见属性

UITableView 的样式

enum UITableViewStyle : Int {
    case Plain // 平铺样式
    case Grouped // 分组样式
}

UITableView 添加或者删除 Cell 时的动画

enum UITableViewRowAnimation : Int {
    case Fade // 淡入淡出
    case Right // 从右添加
    case Left // 从左添加
    case Top // 从上添加
    case Bottom // 从底部添加
    case None // 没有动画
    case Middle // 从中间添加
    case Automatic // 随机添加
}

UITableView 滚动时指定的位置

enum UITableViewScrollPosition : Int {   
    case None // 不指定
    case Top // 指定上面
    case Middle // 指定中间
    case Bottom // 指定底部
}

UITableView 分割线的样式

enum UITableViewCellSeparatorStyle : Int {
    case None // 没有分割线
    case SingleLine // 单行分割线
    case SingleLineEtched // 多行分割线融合
}

UITableView 属性

// 1.设置 UITableView 的位置以及Style
init(frame: CGRect, style: UITableViewStyle)    
var style: UITableViewStyle { get }
// 2.设置数据源对象
unowned(unsafe) var dataSource: UITableViewDataSource?
// 3.设置代理对象
unowned(unsafe) var delegate: UITableViewDelegate?
// 4.设置 Cell 的行高
var rowHeight: CGFloat
// 5.设置 Cell 的标题高度
var sectionHeaderHeight: CGFloat
// 6.设置 Cell 的页尾高度
var sectionFooterHeight: CGFloat
// 7.设置估计的 Cell 的行高
var estimatedRowHeight: CGFloat
// 8.设置估计的 Cell 的标题行高
var estimatedSectionHeaderHeight: CGFloat
// 9.设置估计的 Cell 的页尾行高
var estimatedSectionFooterHeight: CGFloat
// 10.设置 Cell 与 Cell 之间的分割线位置
var separatorInset: UIEdgeInsets
// 11.设置 UITableView 的背景 View 对象
var backgroundView: UIView?

常用数据源方法

要使用数据源方法(DataSoucre方法), 首先我们需要遵守 UITableView 的数据源方法(UITableViewDataSoucre)协议, 这个我们在例子中会讲到

常用数据源方法

// 1.该方法是用来设置 TableView 有多少行 Cell
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int

// 2.该方法是用来设置 TableView 每一行 Cell 的详细内容
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

// 3.该方法是用来设置 TableView 有多少组 Cell
    optional func numberOfSectionsInTableView(tableView: UITableView) -> Int

// 4.该方法是用来设置每一组 Cell 的标题内容
        optional func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?

// 5.该方法是用来设置每一组 Cell 的页尾内容
        optional func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?

// 6.该方法使用来设置 TableView 左滑快捷
    optional func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

// 7.该方法是用来设置 TableView 是否可以拖拽到其他行数, 只要写了该方法, 默认打开
    optional func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)

PS: 以上的1, 2方法是必须得实现的, 否则 UITableView 不会有任何数据, 并且会报错.

常用代理方法

// 1.该方法是用来设置每一行 Cell 的高度
    optional func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat

// 2.该方法是用来设置 Cell 标题内容的高度(如果该方法使用了, 那么在自定义 TableView 的sectionHeaderHeight属性就会被覆盖)
    optional func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat

// 3.该方法是用来设置 Cell 页尾内容的高度(如果该方法使用了, 那么在自定义 TableView 的sectionFooterHeight属性就会被覆盖)
    optional func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat

// 4.该方法是用来设置 TableView 左滑快捷按钮的内容以及详细操作
    optional func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String!

// 5.该方法是用来设置 TableView 每一行 Cell 的编辑模式, 如果不设置, 默认都是删除
    optional func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值