Add/Delete UITableViewCell with animation?

前端 未结 4 801
深忆病人
深忆病人 2020-12-04 15:34

I know this might sound like a dumb question, but I have looked every where. How can I do this?

I know how to do this with a swype-to-delete method, but how cam I do

4条回答
  •  粉色の甜心
    2020-12-04 15:59

    In Swift 2.1+

    tableView.beginUpdates()
    tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], withRowAnimation: .Fade)
    tableView.insertRowsAtIndexPaths([YourIndexPathYouWantToInsertTo], withRowAnimation: .Fade)
    tableView.endUpdates()
    

    And you can create an NSIndexPath easily like so:

    NSIndexPath(forRow: 0, inSection: 0)
    

提交回复
热议问题