在 deleteRowsAtIndexPaths 上崩溃 [英] crash on deleteRowsAtIndexPaths

查看:76
本文介绍了在 deleteRowsAtIndexPaths 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从表中删除行时,我的应用程序崩溃.这是我检测到错误和堆栈跟踪的来源.谢谢!

//从数据库中删除行- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{NSLog(@"
commitEditingStyle");//从Users表中删除指定ID的用户if(editingStyle == UITableViewCellEditingStyleDelete){//获取要从数组中删除的对象.[dbManager 打开:@DB_FILE_NAME];//从数组 usersIDList[row] = userID 中获取用户 ID!NSNumber *usersID = [usersIDList objectAtIndex: [indexPath row]];[dbManager deleteUserWithID: [usersID intValue] 表:@TABLE_USERS fieldName: @"UserID" ];[数据库管理器关闭];//从表中删除对象.[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath]withRowAnimation: UITableViewRowAnimationFade];}}- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation{NSLog(@"
deleteRowsAtIndexPaths");}[会议开始于 2010-11-15 18:01:23 +0200.]2010-11-15 18:01:25.052 电话簿 [12397:207] ******* 可访问性状态更改:开启2010-11-15 18:01:25.101 PhoneBook [12397:207] ************ 加载 AX 为:com.yourcompany.PhoneBook ************2010-11-15 18:01:30.060 电话本[12397:207]删除用户点击2010-11-15 18:01:31.878 电话本[12397:207]提交编辑风格2010-11-15 18:01:31.881 PhoneBook[12397:207] *** 断言失败 -[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableView.m:9202010-11-15 18:01:31.883 PhoneBook[12397:207] *** 由于未捕获的异常NSInternalInconsistencyException"而终止应用程序,原因:无效更新:第 0 节中的行数无效.包含在更新后的现有部分 (6) 必须等于更新前该部分中包含的行数 (6),加上或减去从该部分插入或删除的行数(0 插入,1 删除).*** 第一次抛出时调用堆栈:(0 核心基金会 0x02510b99 __exceptionPreprocess + 1851 libobjc.A.dylib 0x0266040e objc_exception_throw + 472 CoreFoundation 0x024c9238 +[NSException raise:format:arguments:] + 1363 基础 0x000b8e37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 1164 UIKit 0x00338d37 -[UITableView(_UITableViewPrivate)_endCellAnimationsWithContext:] + 87195 UIKit 0x00328511 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 566 UIKit 0x0aaca8fc -[UITableViewAccessibility(Accessibility) deleteRowsAtIndexPaths:withRowAnimation:] + 747 电话簿 0x00003491 -[RootViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 3928 UIKit 0x0032596d -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 1019 UIKit 0x0aacde92 -[UITableViewCellAccessibility(SafeCategory) deleteConfirmationControlWasClicked:] + 6210 UIKit 0x002be7f8 -[UIApplication sendAction:to:from:forEvent:] + 11911 UIKit 0x00349de0 -[UIControl sendAction:to:forEvent:] + 6712 UIKit 0x0034c262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 52713 UIKit 0x0034ae0f -[UIControl touchesEnded:withEvent:] + 45814 UIKit 0x002e23d0 -[UIWindow _sendTouchesForEvent:] + 56715 UIKit 0x002c3cb4 -[UIApplication sendEvent:] + 44716 UIKit 0x002c89bf _UIApplicationHandleEvent + 767217 图形服务 0x02d6c822 PurpleEventCallback + 155018 核心基金会 0x024f1ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 5219 核心基金会 0x02452807 __CFRunLoopDoSource1 + 21520 核心基金会 0x0244fa93 __CFRunLoopRun + 97921 核心基金会 0x0244f350 CFRunLoopRunSpecific + 20822 核心基金会 0x0244f271 CFRunLoopRunInMode + 9723 图形服务 0x02d6b00c GSEventRunModal + 21724 图形服务 0x02d6b0d1 GSEventRun + 11525 UIKit 0x002ccaf2 UIApplicationMain + 116026 电话簿 0x000026ec 主 + 10227 电话簿 0x0000267d 开始 + 53)抛出NSException"的实例后调用终止

解决方案

我以前见过这个,肯定是你忘记更新填表的数据源了.但是那部分代码丢失了.导致这种情况的方法是

<前>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {返回 ;}

My application crashes when I'm deleting row from table. Here is my sources where the bug is detected and stack trace. Thanx!

//delete row from database
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"
commitEditingStyle");

    //delete user from Users table with specified ID
    if(editingStyle == UITableViewCellEditingStyleDelete) 
    {

        //Get the object to delete from the array.
        [dbManager open: @DB_FILE_NAME];    

        //get userID from array usersIDList[row] = userID!
        NSNumber *usersID = [usersIDList objectAtIndex: [indexPath row]];
        [dbManager deleteUserWithID: [usersID intValue] table: @TABLE_USERS fieldName: @"UserID" ];

        [dbManager close];

        //Delete the object from the table.
        [self.tableView deleteRowsAtIndexPaths:
         [NSArray arrayWithObject: indexPath] 
        withRowAnimation: UITableViewRowAnimationFade];
    }
}

- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
{
    NSLog(@"
deleteRowsAtIndexPaths");
}

[Session started at 2010-11-15 18:01:23 +0200.]
2010-11-15 18:01:25.052 PhoneBook[12397:207] ******* Accessibility Status Changed: On
2010-11-15 18:01:25.101 PhoneBook[12397:207] ********** Loading AX for: com.yourcompany.PhoneBook ************
2010-11-15 18:01:30.060 PhoneBook[12397:207] 
deleteBtnUserClick
2010-11-15 18:01:31.878 PhoneBook[12397:207] 
commitEditingStyle
2010-11-15 18:01:31.881 PhoneBook[12397:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableView.m:920
2010-11-15 18:01:31.883 PhoneBook[12397:207] *** 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 (6) must be equal to the number of rows contained in that section before the update (6), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02510b99 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0266040e objc_exception_throw + 47
    2   CoreFoundation                      0x024c9238 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x000b8e37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UIKit                               0x00338d37 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8719
    5   UIKit                               0x00328511 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 56
    6   UIKit                               0x0aaca8fc -[UITableViewAccessibility(Accessibility) deleteRowsAtIndexPaths:withRowAnimation:] + 74
    7   PhoneBook                           0x00003491 -[RootViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 392
    8   UIKit                               0x0032596d -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
    9   UIKit                               0x0aacde92 -[UITableViewCellAccessibility(SafeCategory) deleteConfirmationControlWasClicked:] + 62
    10  UIKit                               0x002be7f8 -[UIApplication sendAction:to:from:forEvent:] + 119
    11  UIKit                               0x00349de0 -[UIControl sendAction:to:forEvent:] + 67
    12  UIKit                               0x0034c262 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    13  UIKit                               0x0034ae0f -[UIControl touchesEnded:withEvent:] + 458
    14  UIKit                               0x002e23d0 -[UIWindow _sendTouchesForEvent:] + 567
    15  UIKit                               0x002c3cb4 -[UIApplication sendEvent:] + 447
    16  UIKit                               0x002c89bf _UIApplicationHandleEvent + 7672
    17  GraphicsServices                    0x02d6c822 PurpleEventCallback + 1550
    18  CoreFoundation                      0x024f1ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    19  CoreFoundation                      0x02452807 __CFRunLoopDoSource1 + 215
    20  CoreFoundation                      0x0244fa93 __CFRunLoopRun + 979
    21  CoreFoundation                      0x0244f350 CFRunLoopRunSpecific + 208
    22  CoreFoundation                      0x0244f271 CFRunLoopRunInMode + 97
    23  GraphicsServices                    0x02d6b00c GSEventRunModal + 217
    24  GraphicsServices                    0x02d6b0d1 GSEventRun + 115
    25  UIKit                               0x002ccaf2 UIApplicationMain + 1160
    26  PhoneBook                           0x000026ec main + 102
    27  PhoneBook                           0x0000267d start + 53
)
terminate called after throwing an instance of 'NSException'

解决方案

I've seen this before and it is definitely that you have forgotten to update source of data which fill up table. But that part of code is missing. The method which caused this is


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ;
}

这篇关于在 deleteRowsAtIndexPaths 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆