23_cell的重用&&tableView的HeaderView或FooterView滑动固定问题

1,tableview 的重用尽量使用左边的取。如果tableview 里面的cell 风格不一样,identifier 设置为不同即可。不然fps 上不来,详见下面图片

2,cell重用的快速写法

ReUseCell:

static NSString *rid=<#rid#>;  

 <#Class#> *cell=[tableView dequeueReusableCellWithIdentifier:rid];  

 if(cell==nil){  

 cell=[[<#Class#> alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:rid];  

 }  

 return cell;

3,解决HeaderView或FooterView滑动固定问题:

  • 方法1:将tableView的style设置为UITableViewStyleGrouped
  • 方法2:就是将UIView设置为整个tableView的headerView或者footerView而不是某个section的headerView或footerView。
  • 方法3:scrollView的代理方法解决HeaderView滑动固定问题

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView)
    {
        CGFloat sectionHeaderHeight = 10; //sectionHeaderHeight
        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);
        }
    }
}
解决FooterView滑动固定问题
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -10, 0);

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

    if (scrollView == self.tableView)
    {
        CGFloat sectionFooterHeight = 10; //sectionFooterHeight
        if (scrollView.contentOffset.y >= sectionFooterHeight && scrollView.contentOffset.y <= 0) {
            scrollView.contentInset = UIEdgeInsetsMake(0, 0, -scrollView.contentOffset.y, 0);
        } else if (scrollView.contentOffset.y <= sectionFooterHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(0, 0, -sectionFooterHeight, 0);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/a_horse/article/details/81902461
今日推荐