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

我只想要一个简单的UITableView,能够向左滑动删除。 一切正常,除了我的原型单元格中的textview上的正确约束似乎在滑动到删除后被移位。 这是我的表格代码:

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 } } 

这是我向左滑动编辑然后向右滑动顶部单元格后的样子(stackoverflow不会让我使用图片)。 请注意,灰色文本框的右侧和每个单元格中的标签不再对齐。 单元格中的灰色文本框具有-8的正确约束,因此我也很困惑为什么其他单元格的文本框上有任何边距。

感谢您给我的任何帮助,我对Swift还是比较新的! 我试图在堆栈溢出上找到类似这个问题的任何东西,而且我已经空了。

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

它似乎仍然是XCode中的一个错误,因为我无法想到你可能想要上述行为。 基本上,如果原型单元格中的文本框约束在Pin自动布局菜单中设置为“约束到边距”,那么在您滑动删除然后滑动后,右边的水平约束将被随机重置(据我所知)背部。

添加这些约束时,只需取消选中约束边距即可解决此问题!