最后一个UITableViewCell的分隔符没有添加?

时间:2015-03-24 15:28:51

标签: ios objective-c iphone uitableview

这就是我的UITableView的样子:

enter image description here

我可能会将图像剪切到最后一个单元格,但最后一个单元格上没有分隔符。

在具有IOS 7.1.1的设备上运行时,它会得到相同的结果,直到我向上和向下滚动视图,然后它会自动添加分隔符。但是在IOS 8.2上运行的模拟器中尝试这一点,因为你什么都不会发生。

所以我想要的只是让分隔符从一开始就可见。

非常感谢

EDIT1

在尝试下面的答案后,它确实有效,但是当有很多单元格并向上滚动时,会出现一个额外的分隔符,如您所见。

enter image description here

检查最后一个单元格。当我上下时,那个额外的分隔符跟着我。

EDIT2

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
        return 76.0f;
    else
        return 25.0f;
}

3 个答案:

答案 0 :(得分:3)

使用以下两个UITableView委托方法

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* view = [UIView new];
[view setBackgroundColor:[UIColor grayColor]];
return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0f;
}

答案 1 :(得分:0)

尝试为1 0r 2像素高度的表添加页脚视图。

答案 2 :(得分:0)

这对我来说完美无缺

self.tableFooterView = [[UIView alloc] init]