美文网首页BUG疑难杂症
UITableView的一些坑

UITableView的一些坑

作者: Coder_Cat | 来源:发表于2018-05-30 15:32 被阅读45次

    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属性

    相关文章

      网友评论

        本文标题:UITableView的一些坑

        本文链接:https://www.haomeiwen.com/subject/ekuajftx.html