29.UITableViewDataSource详解

来源:互联网 发布:python 指数表达 编辑:程序博客网 时间:2024/05/21 17:31

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