滑动即可删除

时间:2011-01-05 19:09:33

标签: iphone uitableview

我看了,我似乎无法找到堆栈上的任何地方溢出一些与我有同样问题的人。所以我使用以下代码:

  -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete); 
}

当我滑动删除按钮时出现,但是当按下它时什么也没做,我忘了做什么?

1 个答案:

答案 0 :(得分:10)

您需要在if语句后实际删除数据。目前,您的if语句根本不执行任何操作,因为它后面只有一个分号。

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //Code to delete data goes here.
        //This could include removing an object from an array, deleting it from core data,
        //and removing the selected row.
    }
}