Iphone 如何从表视图中删除数据?

Iphone 如何从表视图中删除数据?,iphone,iphone-sdk-3.0,ios4,Iphone,Iphone Sdk 3.0,Ios4,我已经用一个添加按钮设置了导航栏,该按钮将数据添加到我的表视图中。我还添加了这一行self.navigationItem.leftBarButtoniem=self.editButtonItem创建编辑按钮。查看该方法时,我注意到-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)rowatindexpath的编辑样式:(nsindepath*)indepath方法。所以我做了下面的修改,但我的

我已经用一个添加按钮设置了导航栏,该按钮将数据添加到我的表视图中。我还添加了这一行
self.navigationItem.leftBarButtoniem=self.editButtonItem
创建编辑按钮。查看该方法时,我注意到
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)rowatindexpath的编辑样式:(nsindepath*)indepath
方法。所以我做了下面的修改,但我的应用程序冻结了。从我的表中删除数据的正确方法是什么

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];


        **[myArray removeObjectAtIndex:[indexPath row]];
        [self.tableView reloadData];**


    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}

首先尝试从数组中删除数据,然后通知表删除相应的行-在这种情况下,不需要重新加载数据调用:

if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [myArray removeObjectAtIndex:[indexPath row]];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];  
}   

首先尝试从数组中删除数据,然后通知表删除相应的行-在这种情况下,不需要重新加载数据调用:

if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [myArray removeObjectAtIndex:[indexPath row]];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];  
}