UITableView(二)

4.@available(iOS 10.0, *)
weak open var prefetchDataSource:UITableViewDataSourcePrefetching?
@available(iOS 11.0, *)
weak open var dragDelegate: UITableViewDragDelegate?
@available(iOS 11.0, *)
 weak open var dropDelegate: UITableViewDropDelegate?

因为暂时是iOS 9.0的版本 所以这几个代理先不研究了

5. open var rowHeight: CGFloat // default is UITableViewAutomaticDimension| 
//The default height (in points) of each row in the table view.
//|negatively impact performance

其实如果每个列表的高度是一定的 我们在这里设置可以加速性能,因为实现代理方法的方式 每一行都需要去给值,默认会有一个值

6.open var sectionHeaderHeight: CGFloat // default is UITableViewAutomaticDimension

7.open var sectionFooterHeight: CGFloat // default is UITableViewAutomaticDimension

8.open var estimatedRowHeight: CGFloat // default is UITableViewAutomaticDimension, set to 0 to disable
Estimation allows you to defer some of the cost of 
geometry calculation from load time to scrolling time.

9.open var estimatedSectionHeaderHeight: CGFloat 
// default is UITableViewAutomaticDimension, set to 0 to disable

10.open var estimatedSectionFooterHeight: CGFloat 
// default is UITableViewAutomaticDimension, set to 0 to disable

11.open var separatorInset: UIEdgeInsets 
// allows customization of the frame of cell separators; see also the separatorInsetReference property.
// Use UITableViewAutomaticDimension for the automatic inset for that edge.

12,open var separatorInsetReference: UITableView.SeparatorInsetReference 
// Changes how custom separatorInset values are interpreted. The default value is UITableViewSeparatorInsetFromCellEdges

上面两个方法是 设置UITableView分割线 …其实也不太用 因为都是自定义cell了
https://www.cnblogs.com/Zev_Fung/p/5650922.html
https://imtangqi.com/2017/02/28/uitableview-cell-separatorinset/

13.open 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.

self.tableView.backgroundView = imageView;
备注:设置背景色
self.tableView.backgroundView优先级高,如果要设置backgroundColor的时候要先把view设置为nil
self.tableView.backgroundColor

open var numberOfSections: Int { get }

open func numberOfRows(inSection section: Int) -> Int

open func rect(forSection section: Int) -> CGRect // includes header, footer and all rows

open func rectForHeader(inSection section: Int) -> CGRect

open func rectForFooter(inSection section: Int) -> CGRect

open func rectForRow(at indexPath: IndexPath) -> CGRect

字面意思都能理解的了..不说了

open func indexPathForRow(at point: CGPoint) -> IndexPath? // returns nil if point is outside of any row in the table

open func indexPath(for cell: UITableViewCell) -> IndexPath? // returns nil if cell is not visible

open func indexPathsForRows(in rect: CGRect) -> [IndexPath]? // returns nil if rect not valid

open func cellForRow(at indexPath: IndexPath) -> UITableViewCell? // returns nil if cell is not visible or index path is out of range

open var visibleCells: [UITableViewCell] { get }

open var indexPathsForVisibleRows: [IndexPath]? { get }

|

An array of index paths, each identifying a visible row in the table view.

|

open func headerView(forSection section: Int) -> UITableViewHeaderFooterView?

open func footerView(forSection section: Int) -> UITableViewHeaderFooterView?

open func scrollToRow(at indexPath: IndexPath, at scrollPosition: UITableView.ScrollPosition, animated: Bool)

|

Summary

Scrolls through the table view until a row identified by index path is at a particular location on the screen.

|

再说 UITableView.ScrollPosition

case none

case top

case middle

case bottom

open func scrollToNearestSelectedRow(at scrollPosition: UITableView.ScrollPosition, animated: Bool)

Scrolls the table view so that the selected row nearest to a specified position in the table view is at that position.

tableView自动滚动 比如歌词啥的可以用到

之后后面有个方法(open func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableView.ScrollPosition))可以调整

open func beginUpdates()

open func endUpdates()

从上述描述中我们大概可以总结出四点

1、beginUpdates 和 endUpdates必须成对使用

2、使用beginUpdates和endUpdates可以在改变一些行(row)的高度时自带动画,并且不需要Reload row(不用调用cellForRow,仅仅需要调用heightForRow,这样效率最高)。

3、在beginUpdates和endUpdates中执行insert,delete,select,reload row时,动画效果更加同步和顺滑,否则动画卡顿且table的属性(如row count)可能会失效。

4、在beginUpdates 和 endUpdates中执行 reloadData 方法和直接reloadData一样,没有相应的中间动画。

一般,在添加,删除,选择 tableView中使用,并实现动画效果。

在动画块内,不建议使用reloadData方法,如果使用,会影响动画。

[self.tableMain beginUpdates];

[self.tableMain deleteRowsAtIndexPaths:indexPathsDelete withRowAnimation:UITableViewRowAnimationFade];

[self.tableMain insertRowsAtIndexPaths:indexPathsInsert withRowAnimation:UITableViewRowAnimationFade];

[self.tableMain endUpdates];

open func insertRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)

open func deleteRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)

@available(iOS 3.0, *)

open func reloadRows(at indexPaths: [IndexPath], with animation: UITableView.RowAnimation)

@available(iOS 5.0, *)

open func moveRow(at indexPath: IndexPath, to newIndexPath: IndexPath)

调用删除API前需要先删除数据源里的数据

deleteRowsAtIndexPaths操作有reload的效果,不先删除数据源里的数据将会导致异常NSInternalInconsistencyException

如果将操作方法放在 beginUpdates() and endUpdates() 之间

无论 插入 删除方法如何排序 都会先执行删除操作 再 进行插入 动画 ,插入动画会延迟执行

这个和在数组中 inserting or removing 不同

in which the operation can affect the array index used for the successive insertion or removal operation.

这是对于删除和添加的操作

移动什么的具体方法到时候使用的时候再分析吧

问题1

open func reloadData()

open func reloadSectionIndexTitles()

|

Reloads the items in the index bar along the right side of the table view.

|

This method gives you a way to update the section index after inserting or deleting sections without having to reload the whole table.

刷新右边栏的那个

open var isEditing: Bool // default is NO. setting is not animated.

open func setEditing(_ editing: Bool, animated: Bool)

|

Toggles the table view into and out of editing mode.

|

Editing. When set, rows show insert/delete/reorder controls based on data source queries

open var allowsSelection: Bool // default is YES. Controls whether rows can be selected when not in editing mode

open var allowsSelectionDuringEditing: Bool // default is NO. Controls whether rows can be selected when in editing mode

open var allowsMultipleSelection: Bool // default is NO. Controls whether multiple rows can be selected simultaneously

This property controls whether multiple rows can be selected simultaneously outside of editing mode. When the value of this property is true, each row that is tapped acquires a selected appearance. Tapping the row again removes the selected appearance. If you access indexPathsForSelectedRows, you can get the index paths that identify the selected rows.

The default value of this property is false.

open var allowsMultipleSelectionDuringEditing: Bool // default is NO. Controls whether multiple rows can be selected simultaneously in editing mode

// Selection

open var indexPathForSelectedRow: IndexPath? { get } // returns nil or index path representing section and row of selection.

@available(iOS 5.0, *)

open var indexPathsForSelectedRows: [IndexPath]? { get } // returns nil or a set of index paths representing the sections and rows of the selection.

// Selects and deselects rows. These methods will not call the delegate methods (-tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath:), nor will it send out a notification.

open func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableView.ScrollPosition)

open func deselectRow(at indexPath: IndexPath, animated: Bool)

open var sectionIndexMinimumDisplayRowCount: Int // show special section index list on right when row count reaches this value. default is 0

显示某个组索引列表在右边当行数达到这个值,默认是NSInteger的最大值

open var sectionIndexColor: UIColor? // color used for text of the section index

open var sectionIndexBackgroundColor: UIColor? // the background color of the section index while not being touched

open var sectionIndexTrackingBackgroundColor: UIColor? // the background color of the section index while it is being touched

open var separatorStyle: UITableViewCell.SeparatorStyle // default is UITableViewCellSeparatorStyleSingleLine

open var separatorColor: UIColor? // default is the standard separator gray

@NSCopying open var separatorEffect: UIVisualEffect? // effect to apply to table separators

首先来看一下iOS8加入的新属性eparatorEffect

tableview.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail.jpg"]];

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];

tableview.separatorEffect = vibrancyEffect;

为tableView设置一张背景图,然后通过UIBlurEffect[蒙层效果]创建一个对象赋给tableView的separatorEffect属性,并且将Cell的背景色设置为clearColor,即可获得非常酷炫的半透明Cell效果了。

open var cellLayoutMarginsFollowReadableWidth: Bool // if cell layout margins are derived from the width of the readableContentGuide. default is NO.

iOS 9.0以后cell的线在iPad上不到边

self.tableView.cellLayoutMarginsFollowReadableWidth = false;

open var cellLayoutMarginsFollowReadableWidth: Bool // if cell layout margins are derived from the width of the readableContentGuide. default is NO.

@available(iOS 11.0, *)

open var insetsContentViewsToSafeArea: Bool // default value is YES

open var tableHeaderView: UIView? // accessory view for above row content. default is nil. not to be confused with section header

open var tableFooterView: UIView? // accessory view below content. default is nil. not to be confused with section footer

标识出列

open func dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell? // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.

@available(iOS 6.0, *)

open func dequeueReusableCell(withIdentifier identifier: String, for indexPath: IndexPath) -> UITableViewCell // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

@available(iOS 6.0, *)

open func dequeueReusableHeaderFooterView(withIdentifier 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.

@available(iOS 5.0, *)

open func register(_ nib: UINib?, forCellReuseIdentifier identifier: String)

@available(iOS 6.0, *)

open func register(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String)

@available(iOS 6.0, *)

open func register(_ nib: UINib?, forHeaderFooterViewReuseIdentifier identifier: String)

@available(iOS 6.0, *)

open func register(_ aClass: AnyClass?, forHeaderFooterViewReuseIdentifier identifier: String)

open var remembersLastFocusedIndexPath: Bool // defaults to NO. If YES, when focusing on a table view the last focused index path is focused automatically. If the table view has never been focused, then the preferred focused index path is used.

// Drag & Drop

// To enable intra-app drags on iPhone, set this to YES.

// You can also force drags to be disabled for this table view by setting this to NO.

// By default, this will return YES on iPad and NO on iPhone.

@available(iOS 11.0, *)

open var dragInteractionEnabled: Bool

// YES if a drag session is currently active. A drag session begins after rows are "lifted" from the table view.

@available(iOS 11.0, *)

open var hasActiveDrag: Bool { get }

// YES if table view is currently tracking a drop session.

@available(iOS 11.0, *)

open var hasActiveDrop: Bool { get }
iOS 11以上的因为暂时没有用到 找到一个链接 可以一阅
https://www.jianshu.com/p/8f566fa95244

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,793评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,567评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,342评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,825评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,814评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,680评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,033评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,687评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,175评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,668评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,775评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,419评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,020评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,206评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,092评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,510评论 2 343