ios - 将行添加到最后一个单元格的底部

标签 ios objective-c xcode

我有 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 时它就消失了

enter image description here enter image description here

最佳答案

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

关于ios - 将行添加到最后一个单元格的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15565322/

相关文章:

ios - 接受提示后核心位置未更新

ios - 具有自定义路径的核心图符号

ios - 使用代码模拟 UIButton Click 事件

ios - PDFKit 高亮注释 : quadrilateralPoints

ios - Swift 中相同类型的同一行中的多个 IBOutlet

iphone - 如何动态更改我的应用程序中的 openURL 实现?

iphone - 一致的 NSUserDefaults 保存

ios - 在 iOS 应用程序中管理网络调用的库/框架

ios - 将 UIButton 对齐到 UITableViewCell 的右侧

ios - xcode 10 错误 : multiple commands produce - react native