gpt4 book ai didi

ios - 点击时滑动以删除崩溃

转载 作者:行者123 更新时间:2023-11-29 01:14:41 25 4
gpt4 key购买 nike

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

PFObject *object = [_tdlArray objectAtIndex:(_tdlArray.count - indexPath.row -1)];
[object deleteInBackground];

//found the code for removing a row.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView reloadData];
[object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!succeeded){

[tableView reloadData];

}

}];

}

}

我能够成功删除数据,但每次我点击删除按钮时我的应用程序都会崩溃。我认为它与 [NSArray arrayWithObject:indexPath]

有关

这些是错误信息

Assertion failure in -[UITableView _endCellAnimationsWithContext:]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

最佳答案

您想删除对象然后重新加载数据。不要异步分派(dispatch)要删除的对象,然后告诉 TableView 您正在删除行,因为该对象可能尚未被删除,因此会出现错误。在删除对象后使用回调 block 更新 TableView ,这样您就可以确定对象已被删除。此外,如果您的本地数据存储未绑定(bind)到服务器上的数据,则还需要从那里删除该对象。

   - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//not sure how you're calculating the index here
PFObject *object = [_tdlArray objectAtIndex:(_tdlArray.count - indexPath.row -1)];
NSMutableArray *mutArray = [_tdlArray mutableCopy];
[mutArray removeObject:object];
_tdlArray = [NSArray arrayWithArray:mutArray];
[object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!succeeded){
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView reloadData];

}

}];

}

}

关于ios - 点击时滑动以删除崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35353457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com