Fork me on GitHub

cell与cell之间的间距问题,以及section跟随屏幕滑动而滑动问题

苹果在cell与cell之间默认没有间距,这样有时候不能满足我们界面要求,所以我们就需要将cell设置为分组模式(也就是每组一行或者多行,分为n组),然后我们就可以在代理中根据自己的需求设计cell之间的距离,但实际是添加了section,看起来像是间距

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 8;

}

 设置完section之后我们需要根据自己的需求设置section是否需要根据我们的界面上滑,而不是卡在上面,这时候我们需要在代理中设置

其中 CGFloat sectionHeaderHeight = 是你上面设置section的数值,我的是8;

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView ==self.tableView)

    {

        CGFloat sectionHeaderHeight = 8;

        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)

        {

            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y,0, 0, 0);

        } else if (scrollView.contentOffset.y>=sectionHeaderHeight)

        {

            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

        }

    }

}

 

 

然后运行就完美解决了cell与cell之间的距离;

posted @ 2016-03-08 10:35  平凡的不平凡  阅读(281)  评论(0编辑  收藏  举报
AmazingCounters.com