1. tableview的footerView
- self.listTableView.tableFooterView = self.tableViewBottomRemindView;可以这样子直接设置tableview的footerView
- _listTableView.estimatedRowHeight = 0;可以解决tableView刷新跳动的问题
2. tableView的contentOffst
- 通过这篇文章就可以了解相关属性的含义scrollView属性contentSize、contentInset、contentOffset的区别就可以了
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding, UIFocusItemScrollableContainer>
@property(nonatomic) CGPoint contentOffset; // default CGPointZero
@property(nonatomic) CGSize contentSize; // default CGSizeZero
@property(nonatomic) UIEdgeInsets contentInset; // default UIEdgeInsetsZero. add additional scroll area
- 总结就是:
- frame:是相对于父视图的位置和大小(40,40,320,480)
- bounds:是相对于自己的位置和大小,自然x,y都为0,也就是(0,0,320,480)
- center:的坐标也是相对于父视图的(200,280)
- contentSize:是scrollView可以滚动的范围,比如一个scrollView的frame是(40,40,320,480),contentSize是(320,960),那么这个scrollView可以上下滚动,并且滚动区域为frame的两倍;
- contnetInset:scrollView的拓展区域,默认是UIEdgeZero,就是没有拓展;
- contentOffset:scrollView目前显示区域相对于frame顶点的偏移量,按照上面的例子,scrollView的偏移量就是(0,480)
3. tableView 计算section的rect相关API
@property (nonatomic, readonly) NSInteger numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
- (CGRect)rectForSection:(NSInteger)section; // includes header, footer and all rows
- (CGRect)rectForHeaderInSection:(NSInteger)section;
- (CGRect)rectForFooterInSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;
stack overflow:rectForSection
4. tableView滚动的问题
1. 通过设置ScrollView的contentOffset滚动到指定的位置
- 滚动到顶部
[self.scrollView setContentOffset:CGPointMake(0,0) animated:YES];
- 滚动到其他section 或者指定的row可以结合上面的计算rect的API来滚动
关于滚动过程中可能跳动或者不准确的bug处理,需要加入如下三句代码取消estimatedRowHeight,因为contentOffset的值是通过预估各cell的高度及header、footer的高度后计算得到的,并非准确的值。
self.tableView.estimatedRowHeight= 0;
self.tableView.estimatedSectionHeaderHeight= 0;
self.tableView.estimatedSectionFooterHeight= 0;