29.UITableViewDataSource详解

UITableViewDataSource

这节我们介绍UITableViewDataSource, 它用于定义tableView的显示.

下面我们查看它的定义:

public protocol UITableViewDataSource : NSObjectProtocol {

    // 设置行数
    @available(iOS 2.0, *)
    public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int

    // 设置显示的cell
    @available(iOS 2.0, *)
    public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

    // 设置分组数, 如果没实现这个方法则是1
    @available(iOS 2.0, *)
    optional public func numberOfSectionsInTableView(tableView: UITableView) -> Int 

    // 指定的section的Header的标题
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    // 指定的section的Footer的标题
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?

    // Editing

    // 指定的indexPath能否编辑行
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

    // Moving/reordering

    // 指定的indexPath的行是否能移动
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool

    // Index

    // 返回右侧的索引标题数组
    @available(iOS 2.0, *)
    optional public func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? 

    // 告诉tableView section右侧索引对应的标题,如"B",1
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int 

    // Data manipulation - insert and delete support

    // 添加/删除后的回调
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

    // Data manipulation - reorder / moving support
    // 行移动回调
    @available(iOS 2.0, *)
    optional public func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值