28.UITableView类详解

UITableView类详解

这个小结我们学习UITable的属性和方法, 粗略的翻一翻就行了, 遇到不懂的再回来查看.

我们查看它的定义:

@available(iOS 2.0, *)
public class UITableView : UIScrollView, NSCoding {

    public init(frame: CGRect, style: UITableViewStyle)
    public init?(coder aDecoder: NSCoder)

    // 获取风格Plain或Grouped
    public var style: UITableViewStyle { get }
    // dataSource
    weak public var dataSource: UITableViewDataSource?
    // delegate
    weak public var delegate: UITableViewDelegate?
    // 行高,没设置的话使用默认的高度
    public var rowHeight: CGFloat 
    // 分组的头的高度,没设置的话使用默认高度
    public var sectionHeaderHeight: CGFloat
    // 分组的底部的高度, 没有设置的话使用默认值
    public var sectionFooterHeight: CGFloat 
    // 预估的行高, 默认值为0
    @available(iOS 7.0, *)
    public var estimatedRowHeight: CGFloat 
    // 预估的分组头部高度,默认为0
    @available(iOS 7.0, *)
    public var estimatedSectionHeaderHeight: CGFloat
    // 预估的分组头部高度,默认为0
    @available(iOS 7.0, *)
    public var estimatedSectionFooterHeight: CGFloat
    // 分割线的边界
    @available(iOS 7.0, *)
    public var separatorInset: UIEdgeInsets

    // 背景View
    @available(iOS 3.2, *)
    public var backgroundView: UIView? // the background view will be automatically resized to track the size of the table view.  this will be placed as a subview of the table view behind all cells and headers/footers.  default may be non-nil for some devices.

    // Data
    // 重新加载数据
    public func reloadData() 

    // 刷新索引栏
    @available(iOS 3.0, *)
    public func reloadSectionIndexTitles() // reloads the index bar.

    // Info
    // 分组数
    public var numberOfSections: Int { get }
    // 分组的行数
    public func numberOfRowsInSection(section: Int) -> Int

    // 分组的rect, 包括header,footer和所有的rows
    public func rectForSection(section: Int) -> CGRect
    // 分组中的header的rect
    public func rectForHeaderInSection(section: Int) -> CGRect
    // 分组中的footer的rect
    public func rectForFooterInSection(section: Int) -> CGRect
    // 分组中的row的rect
    public func rectForRowAtIndexPath(indexPath: NSIndexPath) -> CGRect

    // 指定的点所处的indexPath, 如果不在tableview的任何row中则返回nil
    public func indexPathForRowAtPoint(point: CGPoint) -> NSIndexPath? 
    // 返回指定的cell, 如果该cell不可见则返回nil
    public func indexPathForCell(cell: UITableViewCell) -> NSIndexPath? 
    // 指定的rect中包含的rows, 如果rect无效则返回nil
    public func indexPathsForRowsInRect(rect: CGRect) -> [NSIndexPath]? // returns nil if rect not valid

    // 返回指定的cell, 如果cell不可见或indexPath不在range范围内,则返回nil
    public func cellForRowAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell? 
    // 获得可见cell
    public var visibleCells: [UITableViewCell] { get }
    // 可见行对应的indexPath
    public var indexPathsForVisibleRows: [NSIndexPath]? { get }

    // 获取指定分组的headerView
    @available(iOS 6.0, *)
    public func headerViewForSection(section: Int) -> UITableViewHeaderFooterView?
    // 获得指定分组的footerView
    @available(iOS 6.0, *)
    public func footerViewForSection(section: Int) -> UITableViewHeaderFooterView?

    // 滑动indexPath的指定的row的位置, scrollPosition可为None/Top/Middle/Bottom
    public func scrollToRowAtIndexPath(indexPath: NSIndexPath, atScrollPosition scrollPosition: UITableViewScrollPosition, animated: Bool)
    // 滑动到距离选中行最近的位置
    public func scrollToNearestSelectedRowAtScrollPosition(scrollPosition: UITableViewScrollPosition, animated: Bool)

    // Row insertion/deletion/reloading.

    // 允许插入/删除多个rows和sections的同时运行动画
    public func beginUpdates() 
    // 只能在beginUpdates和endUpdates()之间调用插入/删除/重新加载数据方法或更改编辑状态, 否则可能无效
    public func endUpdates() // only call insert/delete/reload calls or change the editing state inside an update block.  otherwise things like row count, etc. may be invalid.

    // 插入多个分组
    public func insertSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation)
    // 删除多个分组
    public func deleteSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation)
    // 重新加载多个分组
    @available(iOS 3.0, *)
    public func reloadSections(sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation)
    // 移动分组
    @available(iOS 5.0, *)
    public func moveSection(section: Int, toSection newSection: Int)

    // 在indexPaths中插入多个rows
    public func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)
    // 在indexPaths中删除多个rows
    public func deleteRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)
    // 重新加载多个indexPath的行
    @available(iOS 3.0, *)
    public func reloadRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)
    // 移动行
    @available(iOS 5.0, *)
    public func moveRowAtIndexPath(indexPath: NSIndexPath, toIndexPath newIndexPath: NSIndexPath)

    // Editing. When set, rows show insert/delete/reorder controls based on data source queries
    // 编辑模式, 默认为false, 没有动画效果
    public var editing: Bool 
    // 和上面的差不多, 但是它可以设置动画
    public func setEditing(editing: Bool, animated: Bool)

    // 默认为true, 在非编辑模式时行是否可以选中
    @available(iOS 3.0, *)
    public var allowsSelection: Bool 
    // 默认为false, 在编辑模式时行是否可以被选中
    public var allowsSelectionDuringEditing: Bool 

    // 默认为false, 在非编辑模式是否允许选中多个行
    @available(iOS 5.0, *)
    public var allowsMultipleSelection: Bool
    // 默认为false, 在编辑模式是否允许选中多个行
    @available(iOS 5.0, *)
    public var allowsMultipleSelectionDuringEditing: Bool 

    // Selection

    // 返回nil或选中的行对应的indexPath
    public var indexPathForSelectedRow: NSIndexPath? { get } 
    // 返回nil或选中的多个行对应的indexPath数组
    @available(iOS 5.0, *)
    public var indexPathsForSelectedRows: [NSIndexPath]? { get } 

    // 选中指定的行
    public func selectRowAtIndexPath(indexPath: NSIndexPath?, animated: Bool, scrollPosition: UITableViewScrollPosition)
    // 取消选中指定的行
    public func deselectRowAtIndexPath(indexPath: NSIndexPath, animated: Bool)

    // Appearance

    public var sectionIndexMinimumDisplayRowCount: Int // show special section index list on right when row count reaches this value. default is 0
   // 当被选中时分组索引的文本颜色 
    @available(iOS 6.0, *)
    public var sectionIndexColor: UIColor? // color used for text of the section index
    // 当没被触摸时分组索引的背景颜色
    @available(iOS 7.0, *)
    public var sectionIndexBackgroundColor: UIColor? // the background color of the section index while not being touched
    // 分组索引被触摸时的颜色
    @available(iOS 6.0, *)
    public var sectionIndexTrackingBackgroundColor: UIColor? // the background color of the section index while it is being touched

    // 分隔线的类型:None/SingleLine/SingleLineEtched(只能用在grouped风格的UITableView中), 默认是SingleLine
    public var separatorStyle: UITableViewCellSeparatorStyle 
    // 分割线颜色, 默认是灰色
    public var separatorColor: UIColor? 
    // 分割线特效
    @available(iOS 8.0, *)
    @NSCopying public var separatorEffect: UIVisualEffect?

    // 判断是否根据内容留空白
    @available(iOS 9.0, *)
    public var cellLayoutMarginsFollowReadableWidth: Bool // if cell margins are derived from the width of the readableContentGuide.

    // 默认为nil, tableView的headerView,注意它和section header是不同的
    public var tableHeaderView: UIView? 
    // 默认为nil, tableView的footerView, 注意它和section footer是不同的
    public var tableFooterView: UIView? 

    // 重用cell
    public func dequeueReusableCellWithIdentifier(identifier: String) -> UITableViewCell? // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.
    @available(iOS 6.0, *)
    public func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> UITableViewCell // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered
    // 重用section的footer,header
    @available(iOS 6.0, *)
    public func dequeueReusableHeaderFooterViewWithIdentifier(identifier: String) -> UITableViewHeaderFooterView? // like dequeueReusableCellWithIdentifier:, but for headers/footers

    // Beginning in iOS 6, clients can register a nib or class for each cell.
    // If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned.
    // Instances returned from the new dequeue method will also be properly sized when they are returned.
    // 通过nib文件重用cell
    @available(iOS 5.0, *)
    public func registerNib(nib: UINib?, forCellReuseIdentifier identifier: String)
    // 通过类通用cell
    @available(iOS 6.0, *)
    public func registerClass(cellClass: AnyClass?, forCellReuseIdentifier identifier: String)

    // 重用section的footer,header
    @available(iOS 6.0, *)
    public func registerNib(nib: UINib?, forHeaderFooterViewReuseIdentifier identifier: String)
    @available(iOS 6.0, *)
    public func registerClass(aClass: AnyClass?, forHeaderFooterViewReuseIdentifier identifier: String)

    // Focus
    // 默认为false,是否自动记住最后一个获得焦点的indexPath
    @available(iOS 9.0, *)
    public var remembersLastFocusedIndexPath: Bool 
}

可能表述不是那么准确,就当我语言是兼职数学的体育老师交的就好!后面继续探索UITableView!

顺带吐槽一下大深圳的招聘, 投了N多简历,就面了2家, 谈待遇今天确定,明天还能变的,眼泪都快出来了+_+!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值