在Swift中自定义可扩展和可刷卡的UITableViewCell

时间:2016-07-29 11:07:17

标签: ios swift uitableview uicollectionviewcell custom-cell

我创建了一个自定义UITableViewCell,当用户点击它时可以扩展。并且用户也可以滑动以删除该行。但是当用户滑动时,单元格高度发生变化,并且在底部单元格上写入。 At normal case. When user didn't swiper or click on the cell

When user swiped. Cell over written on the bottom cell

When user clicked on the cell

代码:

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)



}

注意:图片中的两个单元格具有相同的名称和信息。

0 个答案:

没有答案