从deleteRowsAtIndexPaths更新UITableView

时间:2015-08-12 09:29:37

标签: ios swift uitableview

我正在尝试从deleteRowsAtIndexPaths更新我的tableView以使用animation.fade。那么请告诉我如何在有两个阵列时更新tableView

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

            let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! PlacesTableViewCell
            cell.title.text = placeArray[indexPath.row]
            cell.backgroundImage.image = photoArray[indexPath.row]

            return cell
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    println("section and row \(indexPath.section) \(indexPath.row) ")

    tableView.beginUpdates()
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
    tableView.endUpdates()
}

2 个答案:

答案 0 :(得分:1)

试试这个

  self.placeArray.removeAtIndex(indexPath.row)
  self.photoArray.removeAtIndex(indexPath.row)
  self.tablename.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)

要删除整个部分,请尝试以下操作:

 self.placeArray.removeAll(keepCapacity: true)
 self.photoArray.removeAll(keepCapacity: true)                                                           
 self.tablename.deleteSections(NSIndexSet(index: indexPath.section), withRowAnimation: UITableViewRowAnimation.Fade)

希望这会有所帮助。

答案 1 :(得分:0)

在删除所需对象后尝试:[tableView reloadData];

相关问题