0

我有 UiTableView。其上的单元格通过单击更改自身高度。我需要添加自定义分隔线。我总是添加到单元格的顶部。所以一切正常,但最后一个单元格底部没有分隔线,用户看不到 tableview 的结尾。我尝试添加下一个代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

然后尝试使用它

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

我在开始新的 UIImageView 中创建

@implementation MovieSessionsVC 
...
    UIImageView *seporatorView;
}

这是我的代码:

[seporatorView removeFromSuperview];
if (indexPath.row == self.sessions.count - 1) {
    seporatorView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seporator.png"]];
    if([self cellIsSelected:indexPath])
        seporatorView.frame = CGRectMake(0, 106, cell.width, 0.5);
    else
        seporatorView.frame = CGRectMake(0, 63, cell.width, 0.5);
    [cell addSubview:seporatorView];
}

我使用 self.sessions.count 作为行数,选择时我的单元格的高度为 64 和 107

所以线出现并且工作正常,但是当我最大程度地拿起我的表格视图时它消失了

在此处输入图像描述 在此处输入图像描述

4

2 回答 2

1

如果它只是您要添加内容的最后一个单元格,在您的情况下是一条线,那么在页脚视图顶部绘制这条线可能是最容易的。您可以创建 aUIView并将其分配给 的tableFooterView属性UITableView。该页脚可能只有 1.0 的高度并填充有颜色。您当然可以在该页脚视图中画一条线drawInRect。为此,您将需要子类化UIView. 但我认为一些UIView具有背景颜色和高度为 1.0 的标准就可以了。

于 2013-03-22T08:12:36.267 回答
0

只需将分隔图像的 resize 属性设置为与下图相同

在此处输入图像描述

任何单元格调整大小时位于底部的分隔符图像..确保单元格调整大小属性全部选中..

于 2013-03-22T08:06:46.140 回答