【问题标题】:How to remove iOS TableView Separator如何删除 iOS TableView 分隔符
【发布时间】:2016-01-21 16:03:14
【问题描述】:
你好,感谢阅读。

我已经尝试删除这些分隔符有一段时间了,我无法删除它们太可怕了。我在stackoverflow中尝试了很多答案,但没有人有帮助:/

问题来了:

我无法删除单元格之间的这些空白:s。

我试过了:

  • 将背景颜色更改为与单元格相同的灰色,但它不起作用
  • 检查单元大小
  • 将 separatorStyle 设置为 UITableViewCellSeparatorStyle.None
  • 使用 tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 返回良好的高度
  • 在主情节提要中禁用分隔符

...我真的不明白如何删除这些空白...

对不起我的英语,

谢谢

我正在添加这个。现在你可以检查我的设置了:(你可以看到分隔符被禁用)

【问题讨论】:

  • 看起来它不是分隔符,而只是单元格之间的空格。你有任何页眉/页脚吗?尝试将标题背景颜色设置为单元格背景颜色,看看空白是否仍然存在。
  • 对我来说,UITableViewCellSeparatorStyle.None 解决方案在 - (id)initWithStyle:(UITableViewStyle)style 函数中具有解码功能,非常完美。我不知道你有没有办法给我发项目!以这种方式帮助您会容易得多:)
  • 勾选,降低单元格高度并添加表格视图背景色。然后在此处附加屏幕。你在使用自定义单元格吗?
  • 我的 tableView 有灰色背景色。我正在使用自定义单元格,是的,但我设置了良好的高度:s
  • 似乎每个其他单元格的大小都不同。这几乎看起来是故意的。这是您生成的代码吗?你能发布你的 cellForIndexPath 函数吗?如果表格中有任何自定义单元格,也许您的单元格中有任何设置功能?

标签: ios swift uitableview tableviewcell


【解决方案1】:

您只需要在属性检查器中进行更改:

【讨论】:

    【解决方案2】:

    试试这个 tableView 方法:

    override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
    {
        return 0.00001
    }
    

    【讨论】:

    • 它不起作用:s。我只需要所有背景都与单元格相同的灰色:s
    • 尝试设置self.view.backgroundColor = UIColor.grayColor();
    【解决方案3】:

    试试这个希望对你有帮助。

    目标 C:

    -(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
    {
        return 0.1f;
    }
    -(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
    {
        return [[UIView alloc] initWithFrame:CGRectZero] ;
    }
    

    斯威夫特:

    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView(frame: CGRectZero)
      }
    
      override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1f
      }
    

    【讨论】:

    • 谢谢,但它不起作用...我已经尝试过将页脚和页眉部分设置为我的 mainstoryboard 中的最小值:/
    【解决方案4】:

    设置tableviewcell分隔符none和图片http://imgur.com/MbVA7pM

    【讨论】:

    • 这只是方法。要再次检查,您需要创建表观察分隔符
    【解决方案5】:

    试试这个:

    func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
        // Remove seperator inset
        if cell.respondsToSelector("setSeparatorInset:") {
            cell.separatorInset = UIEdgeInsetsZero
        }
    
        // Prevent the cell from inheriting the Table View's margin settings
        if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
            cell.preservesSuperviewLayoutMargins = false
        }
    
       // Explictly set your cell's layout margins
       if cell.respondsToSelector("setLayoutMargins:") {
           cell.layoutMargins = UIEdgeInsetsZero
       }
    }
    

    【讨论】:

      【解决方案6】:

      快速隐藏表格视图分隔符

      func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) 
      {
         cell.backgroundColor = UIColor.clearColor()
      }
      

      【讨论】:

      • 我从一开始就这样做了......就像它不是分隔符一样:/
      • 我不明白你在问什么。
      • 如果它有效,请勾选并投票给我的答案。因为它对其他人有帮助。
      【解决方案7】:

      好的,很抱歉,问题出在我的代码上,所以你无法回答我...

      它在我的函数中:tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

      我想在我的单元格上画一个边框,所以我写了:

      var layer: CALayer = cell.layer
              layer.borderColor = UIColor.rgbaColor(red: 288, green: 83, blue: 88, alpha: 1).CGColor
              layer.borderWidth = 2
      

      但是这段代码不起作用,因为 red:288 应该是 red:188,所以我有一个白色边框而不是错误,我没有注意到...抱歉,非常感谢您的帮助: )

      【讨论】:

        【解决方案8】:

        只需将页脚视图设置为空视图:

        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        

        所以空单元格的分隔符会消失(您仍然保留普通单元格的分隔符)。

        【讨论】:

          【解决方案9】:

          在目标c中

          [self.tableView setSeparatorColor:[UIColor myColor]];
          

          在斯威夫特中

          tableView.separatorColor = UIColor.clear
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2016-11-09
            • 1970-01-01
            • 1970-01-01
            • 2014-02-10
            • 2013-01-02
            • 2016-12-25
            • 1970-01-01
            相关资源
            最近更新 更多