Ios 我的手机发送了错误的信息?

Ios 我的手机发送了错误的信息?,ios,uitableview,Ios,Uitableview,当我调用CellForRowatingIndexPath的indexpath时:为了删除单元格,它会在所选单元格之前删除de cell。。。其工作原理如下: 我将信息添加到tableview: - (BOOL)textFieldShouldReturn:(UITextField *)textField{ [self.tasks insertObject:textField.text atIndex:0]; [self.userdefaults setObject:self.ta

当我调用CellForRowatingIndexPath的indexpath时:为了删除单元格,它会在所选单元格之前删除de cell。。。其工作原理如下:

我将信息添加到tableview:

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [self.tasks insertObject:textField.text atIndex:0];
    [self.userdefaults setObject:self.tasks forKey:@"tasks"];
    [self.userdefaults synchronize];

    NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:(0) inSection:0];
    [self.tableview beginUpdates];
    [self.tableview insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
    [self.userdefaults synchronize];
    [self.tableview endUpdates];
}
然后我用CocoaControl(MCSwipeTableViewCell)的一些手势编辑信息:


因此,当我试图删除它删除一个单元格之前,它被选中,我需要别人的帮助,谢谢

尝试使用:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]with RowAnimation:UITableViewRowAnimationRight]取而代之?

您可以在完成块中使用
[tableView indexPathForCell:cell]
来获取适当的indepath。

非常确定您需要将
indepath
捕获为局部变量。不相关但仅供参考-无需调用
synchronize
。如果只调用一个表视图insert/delete/reload,则无需使用
BeginUpdate/EndUpdate
。@HotLicks块将保留
indexPath
。所以我删除了begin和ENDDUPDATES?这可能就是问题所在?为什么不在完成块中使用[tableView indexPathForCell:cell]?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//This is for deleting a cell
[cell setSwipeGestureWithView:cross color:redColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState2 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {


        [tableView beginUpdates];

        I tried to use this index and didnt work-->//NSIndexPath *myindex = [self.tableview indexPathForSelectedRow];

        [self.tasks removeObjectAtIndex:[self keyForIndexPath:indexPath].row];
        [self.userdefaults setObject:self.tasks forKey:@"tasks"];
        [self.userdefaults synchronize];

        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
        [tableView endUpdates];

        NSLog(@"Did swipe \"Cross\" cell");
    }];


}

- (NSIndexPath *)keyForIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath class] == [NSIndexPath class]) {
        return indexPath;
    }
    return [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
}