ipad – 核心数据示例,无效更新:第0部分中的行数无效

ipad – 核心数据示例,无效更新:第0部分中的行数无效,第1张

概述我是iOS和XCode的新手,我正在通过核心数据教程,我真的很难过.我不断收到以下错误日志中的错误: Exception Type: EXC_CRASH (SIGABRT)Exception Codes: 0x0000000000000000, 0x0000000000000000Crashed Thread: 0 Dispatch queue: com.apple.main-threa 我是iOS和XCode的新手,我正在通过核心数据教程,我真的很难过.我不断收到以下错误日志中的错误:

Exception Type:  EXC_CRASH (SIGABRT)Exception Codes: 0x0000000000000000,0x0000000000000000Crashed Thread:  0  dispatch queue: com.apple.main-threadApplication Specific information:iPhone Simulator 235,iPhone OS 4.2 (iPad/8C134)*** 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 (0) must be equal to the number of rows contained in that section before the update (0),plus or minus the number of rows inserted or deleted from that section (1 inserted,0 deleted).'*** Call stack at first throw:(        0   CoreFoundation                      0x010a6be9 __exceptionPreprocess + 185        1   libobjc.A.dylib                     0x00e9b5c2 objc_exception_throw + 47        2   CoreFoundation                      0x0105f628 +[NSException raise:format:arguments:] + 136        3   Foundation                          0x000b447b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116        4   UIKit                               0x00336a0f -[UItableVIEw(_UItableVIEwPrivate) _endCellAnimationsWithContext:] + 8424        5   UIKit                               0x00325f81 -[UItableVIEw insertRowsAtIndexPaths:withRowAnimation:] + 56        6   SimpleRes                           0x00002496 -[RootVIEwController addReservation] + 465        7   UIKit                               0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119        8   UIKit                               0x004c7167 -[UIbarbuttonItem(UIInternal) _sendAction:withEvent:] + 156        9   UIKit                               0x002b9a6e -[UIApplication sendAction:to:from:forEvent:] + 119        10  UIKit                               0x003481b5 -[UIControl sendAction:to:forEvent:] + 67        11  UIKit                               0x0034a647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527        12  UIKit                               0x003491f4 -[UIControl touchesEnded:withEvent:] + 458        13  UIKit                               0x002de0d1 -[UIWindow _sendtouchesForEvent:] + 567        14  UIKit                               0x002bf37a -[UIApplication sendEvent:] + 447        15  UIKit                               0x002c4732 _UIApplicationHandleEvent + 7576        16  GraphiCSServices                    0x018bda36 PurpleEventCallback + 1550        17  CoreFoundation                      0x01088064 __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52        18  CoreFoundation                      0x00fe86f7 __CFRunLoopDoSource1 + 215        19  CoreFoundation                      0x00fe5983 __CFRunLoopRun + 979        20  CoreFoundation                      0x00fe5240 CFRunLoopRunspecific + 208        21  CoreFoundation                      0x00fe5161 CFRunLoopRunInMode + 97        22  GraphiCSServices                    0x018bc268 GSEventRunModal + 217        23  GraphiCSServices                    0x018bc32d GSEventRun + 115        24  UIKit                               0x002c842e UIApplicationMain + 1160        25  SimpleRes                           0x00001ab0 main + 102        26  SimpleRes                           0x00001a41 start + 53)

这是我的addReservation代码:

-(voID)addReservation{    // Create and configure a new instance of the Event entity.    Reservations *reservation = (Reservations *)[NSEntityDescription insertNewObjectForEntityForname:@"Reservations" inManagedobjectContext:managedobjectContext];    [reservation setEnd_Time: [[NSDate alloc]init]];    [reservation setReservation_Date:[[NSDate alloc]init]];    [reservation setStart_Time:[NSDate date]];    [reservation setParty_Size: [NSNumber numberWithInt:4]];    [reservation setPhone_Number: [NSNumber numberWithInt: 1234567890]];    [reservation setname: @"Keith"];    [reservation setNotes: @"He's really hot!"];    [reservation setPerson_Responsible: @"lisa"];    [reservation settables_Excluded: @"3,5,8"];    NSError *error = nil;    if (![managedobjectContext save:&error]) {        }    [resArray insertObject:reservation atIndex:0];    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];    [self.tableVIEw insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]                          withRowAnimation:UItableVIEwRowAnimationFade];    [self.tableVIEw scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollposition:UItableVIEwScrollpositiontop animated:YES];}

我相信我的resArray没有从我以编程方式输入的方法获取数据,但我不确定,我不确定如何修复它.

任何帮助表示赞赏.

解决方法 我会看一下你的实现

- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section

当从numberOfRowsInSection返回的值不等于先前的值加上使用insertRowsAtIndexPaths添加的行数时,会出现您指定的错误.如果numberOfRowsInSection的实现使用[myArray count],那么请确保使用的数组实例与添加预留条目的数组实例相同.如果您还没有实现此方法,那么这将是您的问题.以下是该方法应如何显示的示例

- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw  numberOfRowsInSection:(NSInteger)section {    return [resArray count];}

作为备份,您可以添加日志语句,列出添加之前和之后的数组大小,以及numberOfRowsInSection函数内部.

总结

以上是内存溢出为你收集整理的ipad – 核心数据示例,无效更新:第0部分中的行数无效全部内容,希望文章能够帮你解决ipad – 核心数据示例,无效更新:第0部分中的行数无效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1081635.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存