自定义 UITableViewCell 将 space 添加到右侧

Custom UITableViewCell adds space to right side

我有一个带有标签和按钮的自定义 table 视图单元格,但由于某种原因,右侧自定义单元格下方的分隔线被截断了。我检查了 Storyboard 中的 Custom Separator Inset,左边是 15,右边是 0。我什至尝试使用 tableView.layoutMargins = UIEdgeInsetsZero 和 cell.layoutMargins = UIEdgeInsetsZero 以编程方式设置 Inset,但这也不起作用。非常感谢您的建议。谢谢

[见图][1]

更新 - 已解决:所以我使用 iPhone 5 尺寸的屏幕在故事板中制作了自定义单元格,模拟的是 iPhone 6,所以我猜单元格宽度不够长.

将此代码放入您的 table 视图的数据源中。我个人使用此代码,无论您的情节提要设置如何,它都可以使用。

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
    if tableView.respondsToSelector(Selector("setSeparatorInset:")) { tableView.separatorInset = UIEdgeInsetsZero }
    if tableView.respondsToSelector(Selector("setLayoutMargins:")) { tableView.layoutMargins = UIEdgeInsetsZero }
    if cell.respondsToSelector(Selector("setLayoutMargins:")) { cell.layoutMargins = UIEdgeInsetsZero }
}