简体   繁体   English

有时会崩溃,导致UITableView处删除行(仅在iOS7中)

[英]Crash sometimes deleting row at UITableView (only in iOS7)

I had my app running cool in iOS6 , but when I updated for iOS7 with the same code I was working with, I get this error when I try to delete a row in a table : 我的应用程序在iOS6运行的很酷,但是当我使用与我相同的代码为iOS7更新时,尝试删除表中的行时出现此错误:

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

the following code like that 下面的代码是这样的

- (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];

    }
}

In the viewDidAppear method,logs(array) get values from db,so when I delete the row,I should 1.delete data from db 2.delte object from logs 3.execute deleteRowsAtIndexPaths method viewDidAppear方法中,logs(array)从db获取值,所以当我删除行时,我应该1.从db中删除数据2.从日志中删除对象3.执行deleteRowsAtIndexPaths方法

But sometimes I get crash when I delete the row(only in IOS7 ) can anybody help me? 但是有时删除行时会崩溃(仅在IOS7 ),有人可以帮助我吗?

Crash log: 崩溃日志:

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

you can reload the tableview once again after deleting the rows. 您可以在删除行后再次重新加载tableview。 add this statement in your code. 在您的代码中添加此语句。 [tableview reloaddata]; [tableview reloaddata];

- (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

    }
}

在您的commitEditingStyle方法末尾添加此行,这将帮助您解决。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM