iOS swift 删除 UITableView 单元格分隔空间

Posted

技术标签:

【中文标题】iOS swift 删除 UITableView 单元格分隔空间【英文标题】:iOS swift remove UITableView Cell separator space 【发布时间】:2015-06-30 17:55:31 【问题描述】:

我正在尝试删除 tableView 分隔符,我通过将分隔符样式设置为无来做到这一点,这将删除分隔符但在单元格之间留下空间。

我的问题是如何删除单元格之间的空间?

任何帮助将不胜感激。

【问题讨论】:

【参考方案1】:

awakeFromNib 功能设置UITableViewCell 选项到UIEdgeInsetsZero 应该可以工作

  self.layoutMargins = UIEdgeInsetsZero
  self.separatorInset = UIEdgeInsetsZero

【讨论】:

如果您可以批准答案,其他人可以看到它正在工作,祝您使用 Swift 编码愉快! yes 会这样做,只是等待 *** 让我批准答案【参考方案2】:

我在cellForRowAtIndexPath做这个

    // remove the spaces on the cell separators
    if (cell.respondsToSelector("setPreservesSuperviewLayoutMargins:")) 
        cell.preservesSuperviewLayoutMargins = false
    
    cell.separatorInset = UIEdgeInsetsZero
    if(cell.respondsToSelector("setLayoutMargins:"))            
        cell.layoutMargins = UIEdgeInsetsZero
    

【讨论】:

以上是关于iOS swift 删除 UITableView 单元格分隔空间的主要内容,如果未能解决你的问题,请参考以下文章

Swift UITableView 删除行项 - tableview 数据源是 Core Data

iOS Swift 2 - 删除 tableView 行时出错

iOS UITableView-纯代码创建UITableView,Cell点击事件,Cell左滑删除

iOS UITableView-纯代码创建UITableView,Cell点击事件,Cell左滑删除

iOS:Swift 中 UITableViewCell 的垃圾桶可以删除按钮

删除 UITableView 行时删除通知(Swift)