【问题标题】:Removing the separator between section header & uitableviewcell删除节标题和 uitableviewcell 之间的分隔符
【发布时间】:2018-06-20 07:54:11
【问题描述】:

如何去除图片中的线条?我尝试了以下建议,但没有一个对我有用,

How do I remove the borders of a UITableView?

Remove separator line for only one cell

Hide separator line on one UITableViewCell

这是我在cellForRowAt中的当前代码:

       if (indexPath.row == place_sections[indexPath.section].rows.count - 1) {
            cell.separatorInset.left = 1000
            //cell.layer.borderWidth = 0
            //cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);

        }
        if (indexPath.row == 0) {
            cell.separatorInset.left = 1000
            //cell.layer.borderWidth = 0
            //cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);

            //                self.tableview.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableview.frame.width, height: 1))
        }

谢谢

【问题讨论】:

  • 你试过设置tableView.separatorColor = tableView.backgroundColor吗?它不会删除分隔符,但它应该可以解决,因为您只想要可见的结果
  • 阅读下面第一个答案的评论。这不是我想要的。
  • @marko calvocruz 我明白你的问题,我会尽力解决它...

标签: ios uitableview


【解决方案1】:

这是客观的c代码,对你有帮助

http://www.iostute.com/2015/04/expandable-and-collapsable-tableview.html

对于快速和客观的 c

http://www.anexinet.com/blog/expandable-collapsible-uitableview-sections/

第一个链接有自定义标题视图,所以边框线不会出现在这里。

在 viewForHeaderInSection 函数中注释这段代码

// /********** Add a custom Separator with Section view *******************/
//    UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(15, 40, _expandableTableView.frame.size.width-15, 1)];
//    separatorLineView.backgroundColor = [UIColor blackColor];
//    [sectionView addSubview:separatorLineView];

查看屏幕截图

【讨论】:

  • 问题是我想保留行之间的分隔符。我只是不喜欢(最后一行和部分标题)和(部分标题和第一行)之间的分隔符。
  • @iOSDeveloper 他想在单元格之间保留分隔符。不是单元格和节标题之间的那个..
  • 查看了这两个链接后,都没有真正帮助我解决我遇到的问题。
  • 此解决方案不仅从标题中删除分隔符,还从每个部分的最后一个单元格中删除分隔符。这在用户体验方面是不一致的行为,我想即使这也不是问题中所期望的。
【解决方案2】:

我能解决这个问题的最接近的方法是将 UITableView 的样式从“分组”更改为“普通”。

如果您能找到更好的解决方案,我不会推荐它,因为现在部分标题在滚动时会粘在屏幕顶部,这是不可取的(我相信描述这一点的正确方法是“部分标题浮动” )。

【讨论】:

    【解决方案3】:

    标题和单元格之间的分隔符属于部分中的第一个单元格。 当我使用标准 UITableViewHeaderFooterView 和 UITableViewCell 时,我设法通过以下代码隐藏了标题和单元格之间的线:

    let contentView = cell.contentView
    if
        // this separator is subview of first UITableViewCell in section
        indexPath.row == 0,
        // truing to find it in subviews
        let divider = cell.subviews.filter({ $0.frame.minY == 0 && $0 !== contentView }).first
    {
        divider.isHidden = true
    }
    

    这段代码必须在tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)中调用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 2016-03-04
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多