UITableView 中的自定义单元格在滑动后立即移动以进行编辑

Custom cell in UITableView shifts right after swipe to edit

我只想要一个简单的 UITableView,可以向左滑动删除。一切正常,除了我的原型单元格中 textview 的右约束似乎在滑动删除后移动了。这是我的 table:

代码
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    //Uses prototype cell from Interface Builder called "CommentTableCell"
    let tableCell = tableView.dequeueReusableCellWithIdentifier("CommentTableCell", forIndexPath: indexPath) as! CommentTableCell
    tableCell.userInteractionEnabled = true
    tableCell.selectionStyle = .None
    //Sets the text for the cells in the comment table
    tableCell.commentText.text = comments[indexPath.row]
    tableCell.timeLabel.text = commentTimes[indexPath.row]

    return tableCell

}


//As many rows in the table as there are comments
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return comments.count

}

//Allows the user to delete comments
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if (editingStyle == UITableViewCellEditingStyle.Delete) {

        comments.removeAtIndex(indexPath.row)
        commentsTable.deleteRowsAtIndexPaths([indexPath],  withRowAnimation: UITableViewRowAnimation.Automatic)
    }

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.layer.borderWidth = 0.75
    self.view.layer.borderColor = borderColor.CGColor
    self.view.layer.cornerRadius = 5.0

    //Gets rid of the line between comment cells
    commentsTable.separatorStyle = UITableViewCellSeparatorStyle.None
    commentsTable.backgroundView = nil

    //Sets the height of the row to fit text boxes
    self.commentsTable.estimatedRowHeight = self.commentsTable.rowHeight
    self.commentsTable.rowHeight = UITableViewAutomaticDimension

    }
}

This 是我向左滑动进行编辑然后向右滑动顶部单元格后的样子(Whosebug 还不允许我使用图片)。请注意,每个单元格中灰色文本框和标签的右侧不再对齐。单元格中的灰色文本框具有 -8 的右约束,所以我也很困惑为什么其他单元格的文本框上有任何边距。

感谢您能给我的任何帮助,我对 Swift 还是个新手!我试图在堆栈溢出上找到类似这个问题的任何内容,但结果是空的。

好的,所以我找到了解决这个问题的方法,我想我会 post 在这里以防其他人遇到同样的问题。

对我来说,它仍然像是 XCode 中的错误,因为我想不出任何时候您可能想要上述行为。基本上,如果在 Pin 自动布局菜单中将原型单元格中的文本框约束设置为 "constrain to margins" 那么在你滑动删除然后滑动后,右侧的水平约束将随机重置(据我所知)返回。

添加这些约束时只需取消选中对边距的约束,它应该可以解决此问题!