崩溃有时在UITableView上删除行(仅在iOS7中)

时间:2014-02-13 10:06:02

标签: ios uitableview

我的应用程序在iOS6中运行很酷,但是当我使用与我一起使用的相同代码更新iOS7时,当我尝试删除表中的行时出现此错误:

UIViewAnimation initWithView:indexPath:endRect:endAlpha:startFraction:endFraction:curve:animateFromCurrentPosition:shouldDeleteAfterAnimation:editing:

以下代码

- (void)tableView:(UITableView *)sender commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.

        [self.tableView beginUpdates];
        PACallLog *aLog = _logs[indexPath.row];
        [[PAFMDBManager sharedManager] deleteACallLog:aLog];
        [_logs removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView endUpdates];

    }
}

viewDidAppear方法中,logs(array)从db获取值,所以当我删除行时,我应该 1.删​​除db中的数据 2.从日志中提取对象 3.执行deleteRowsAtIndexPaths方法

但有时我删除行时会崩溃(仅限于IOS7) 有人可以帮助我吗?

崩溃日志:

Last Exception Backtrace:
0   CoreFoundation                  0x3065ae7e __exceptionPreprocess + 126
1   libobjc.A.dylib                 0x3a9b76c2 objc_exception_throw + 34
2   CoreFoundation                  0x3065ad50 +[NSException raise:format:arguments:] + 100
3   Foundation                      0x310030aa -[NSAssertionHandler         handleFailureInMethod:object:file:lineNumber:description:] + 86
4   UIKit                           0x32fdc8ce -[UIViewAnimation initWithView:indexPath:endRect:endAlpha:startFraction:endFraction:curve:animateFromCurrentPosition:shouldDeleteAfterAnimation:editing:] + 350
5   UIKit                           0x32fe020e -[_UITableViewUpdateSupport(Private) _setupAnimationsForExistingHeadersAndFooters] + 5278
6   UIKit                           0x32fda7d6 -[_UITableViewUpdateSupport _setupAnimations] + 182
7   UIKit                           0x32fda286 -[UITableView _updateWithItems:updateSupport:] + 1358
8   UIKit                           0x32fb2392 -[UITableView _endCellAnimationsWithContext:] + 8014
9   2cu                             0x00137a14 0x4000 + 1260052
10  UIKit                           0x32fd87c2 -[UITableView animateDeletionOfRowWithCell:] + 90
11  UIKit                           0x32fd8754 -[UITableViewCell _swipeDeleteButtonPushed] + 60
12  UIKit                           0x32e13d9e -[UIApplication sendAction:to:from:forEvent:] + 86
13  UIKit                           0x32e13d3a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 34
14  UIKit                           0x32e13d0e -[UIControl sendAction:to:forEvent:] + 42
15  UIKit                           0x32dff73e -[UIControl _sendActionsForEvents:withEvent:] + 370
16  UIKit                           0x32e13756 -[UIControl touchesEnded:withEvent:] + 590
17  UIKit                           0x32e13420 -[UIWindow _sendTouchesForEvent:] + 524
18  UIKit                           0x32e0e44c -[UIWindow sendEvent:] + 828
19  UIKit                           0x32de3d74 -[UIApplication sendEvent:] + 192
20  UIKit                           0x32de2564 _UIApplicationHandleEventQueue + 7112

3 个答案:

答案 0 :(得分:0)

删除行后,您可以再次重新加载tableview。在代码中添加此语句。 [tableview reloaddata];

答案 1 :(得分:0)

- (void)tableView:(UITableView *)sender commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.

        [self.tableView beginUpdates];
        PACallLog *aLog = _logs[indexPath.row];
        [[PAFMDBManager sharedManager] deleteACallLog:aLog];
        [_logs removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView endUpdates];

        // Refill your array and table reload

    }
}

答案 2 :(得分:0)

IT"工作 在您的commitEditingStyle方法的末尾添加此行,这将有助于您解决。

[TableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];