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

你可能感兴趣的:(UITableView(二))