我有 UiTableView。通过单击其上的单元格可以更改自身的高度。我需要添加自定义分隔线。我总是添加到单元格的顶部。所以一切工作正常,但最后一个单元格底部没有分隔线,用户看不到表格 View 的末尾。我尝试在
中添加下一个代码- (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
所以线条出现并且工作正常,但是当我拿起最大的桌面 View 时它就消失了
最佳答案
如果它只是您想要添加内容的最后一个单元格(在您的情况下是一条线),那么在页脚 View 顶部绘制该线可能是最简单的。您可以创建一个 UIView
并将其分配给 UITableView
的 tableFooterView
属性。该页脚的高度可能仅为 1.0,并填充有颜色。
您当然可以在该 footerView 的 drawInRect
中画一条线。为此,您需要子类化 UIView
。但我认为一些背景颜色和高度为 1.0 的标准 UIView
就可以了。
关于ios - 将行添加到最后一个单元格的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15565322/