我创建了一个自定义UITableViewCell,当用户点击它时可以扩展。并且用户也可以滑动以删除该行。但是当用户滑动时,单元格高度发生变化,并且在底部单元格上写入。
代码:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .Normal, title: "Delete") { (action, index) in
self.deleteIndexPath = indexPath
self.deleteKey(self.keys[(self.deleteIndexPath?.row)!])
self.tableView.deleteRowsAtIndexPaths([self.deleteIndexPath!], withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.reloadData()
}
delete.backgroundColor = UIColor.redColor()
self.swipedIndexPath = indexPath
return [delete]
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let index = indexPath
if selectedIndexPath != nil{
if index == selectedIndexPath{
return 143
}else{
return 71
}
}else{
return 71
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
withRowAnimation: UITableViewRowAnimation.Automatic )
switch selectedIndexPath {
case nil:
selectedIndexPath = indexPath
default:
if selectedIndexPath! == indexPath{
selectedIndexPath = nil
}else{
selectedIndexPath = indexPath
}
}
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
注意:图片中的两个单元格具有相同的名称和信息。