UITableView小知识

tableViewCell分割线顶到头

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setSeparatorInset:UIEdgeInsetsZero];
[cell setLayoutMargins:UIEdgeInsetsZero];
cell.preservesSuperviewLayoutMargins = NO;
}

-(void)viewDidLayoutSubviews {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}

解决高亮的问题

-(void)setSelected:(BOOL)selected{
if (selected) {
    self.contentView.backgroundColor = GrayBackGroundColor;
}
else
{
    self.contentView.backgroundColor = BlackBackGroundColor;
}
}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (selected) {
    self.contentView.backgroundColor = GrayBackGroundColor;
}
else
{
    self.contentView.backgroundColor = BlackBackGroundColor;
}
}

-(void)setHighlighted:(BOOL)highlighted{
if (highlighted) {
    self.contentView.backgroundColor = GrayBackGroundColor;
}
else
{
    self.contentView.backgroundColor = BlackBackGroundColor;
}
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
if (highlighted) {
    self.contentView.backgroundColor = GrayBackGroundColor;
}
else
{
    self.contentView.backgroundColor = BlackBackGroundColor;
}
}

sectionHeader 随页面滚动

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.tableView)
{
    CGFloat sectionHeaderHeight = 30;
    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);
    }
}
}

解决重用重叠

[self.tableView cellForRowAtIndexPath:indexPath];

你可能感兴趣的:(UITableView小知识)