ios - 在一个 UITableViewCell 上隐藏分隔线

我正在自定义一个 UITableView。我想隐藏 last 单元格上的分隔线...我可以这样做吗?

我知道我可以做到 tableView.separatorStyle = UITableViewCellStyle.None 但这会影响 所有 tableView 的单元格。我希望它只影响我的最后一个单元格。

最佳答案

viewDidLoad中,添加这一行:

self.tableView.separatorColor = [UIColor clearColor];

cellForRowAtIndexPath中:

适用于 iOS 较低版本

if(indexPath.row != self.newCarArray.count-1){
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 2)];
    line.backgroundColor = [UIColor redColor];
    [cell addSubview:line];
}

适用于 iOS 7 更高版本(包括 iOS 8)

if (indexPath.row == self.newCarArray.count-1) {
    cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);
}

https://stackoverflow.com/questions/8561774/

相关文章:

ios - 从 "bouncing"垂直停止 UIWebView?

ios - 卸载应用程序时删除钥匙串(keychain)项目

ios - 如何更改导航栏上 "back"按钮的标题

objective-c - 实现 API 时如何避免在 block 中捕获 self ?

ios - 使 UINavigationBar 透明

ios - 在 Swift 中使用 UI_USER_INTERFACE_IDIOM() 检测当前设备

ios - 突出显示时如何更改 UIButton 的背景颜色?

objective-c - 开始使用 instancetype 而不是 id 会有好处吗?

ios - 设置自定义 UITableViewCells 高度

iphone - 如何在我的 iPhone 应用程序中使用 NSError?