I just want a simple UITableView with the ability to slide left to delete. Everything works okay except the right constraint on the textview in my prototype cell seems to get shifted after swiping to delete. Here's my code for the 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 is what it looks like after I've swiped left to edit and then swiped back right on the top cell (stackoverflow won't let me use pictures yet). Note the right sides of the gray text boxes and labels in each cell are no longer aligned. The gray text box in the cells has a right constraint of -8 so I'm also confused why there's any margin on the other cell's text boxes at all.
Thanks for any help you can give me, I'm still fairly new to Swift! I've tried to find anything like this question on stack overflow and I've come up empty.