UITableView的一些坑

1、如果使用UITableViewStylePlain样式的表格,那么section的header是会在表格滑动的时候在顶部悬浮,而不是跟随表格的滑动而一起滑动。
2、如果使用了UITableViewStyleGrouped样式的表格,tableView:viewForHeaderInSection:的section的值会从1开始,section的header是会随表格的滑动而一起滑动。

  1. UITableViewStyleGrouped表格会有默认的header及footer高度(好像是13),设置属性有效,设置代理方法无效,这应该是个bug。
//设置sectionHeader高度
 _tableView.sectionHeaderHeight = 45;
//设置sectionFooter高度
_tableView.sectionFooterHeight = 0
/***下面方法无效***/
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;//设置sectionFooter高度为0
}

4.- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;滚动到指定的indexPath 方法只有在UITableViewStyleGrouped样式下能正确滚动,如果是UITableViewStylePlain样式滚动的位置达不到想要的效果。
5.UITableViewStyleGrouped样式下,手动设置偏移量等滚动方法可能会产生顶部留白的情况。如:[self.tableView scrollRectToVisible:CGRectMake(0, 0, 0.1, 0.1) animated:YES];或者[self.tableView setContentOffset:CGPointZero animated:YES];都可能产生顶部留白的情况。原因可参考下文:
解决ScrollView设置delaysContentTouches为NO后,按在button上scrollview无法滑动问题
UIScrollView的delaysContentTouches与canCencelContentTouches属性

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容