为什么在iOS 7下刷卡到删除会崩溃?

为什么在iOS 7下刷卡到删除会崩溃?,第1张

概述我在刷卡删除后开始收到崩溃报告,并且能够重新创建它.然后因为我使用了Apple的iPhoneCoreDataRecipes示例作为模型,我尝试了原始的示例代码,并且每次都会崩溃. 要重新创建,只需在CoreDataRecipes下载并运行项目.然后(1)点击,例如,Macaroons查看配方中的成分,(2)滑动以删除成分和(3)刷上另一种成分.崩溃. 我的问题是:我是否错过了示例项目代码中的错误 @H_419_2@ 我在刷卡到删除后开始收到崩溃报告,并且能够重新创建它.然后因为我使用了Apple的iPhoneCoreDataRecipes示例作为模型,我尝试了原始的示例代码,并且每次都会崩溃.

要重新创建,只需在CoreDataRecipes下载并运行项目.然后(1)点击,例如,Macaroons查看配方中的成分,(2)滑动以删除成分和(3)刷上另一种成分.崩溃.

我的问题是:我是否错过了示例项目代码中的错误,或者这实际上是 *** 作系统中的错误?其次,是否有一种解决方法可以识别这种情况并对其进行防御,但是仍然允许滑动删除? (现在,我只是通过从tableVIEw返回UItableVIEwCellEditingStyleNone来禁用滑动删除:editingStyleForRowAtIndexPath:除非我已经处于编辑模式.)

在这样的列表中,“编辑”按钮向tableVC发送setEditing:YES,在新行中添加“添加项”按钮(显然允许向列表中添加新项),并且现有项获得添加红色减号图标以允许删除.完成后,Done发送setEditing:NO,删除新行和图标.一切正常. (参见下面的调试输出中的案例1).

相反,如果用户只想删除单个项目,则可以通过滑动项目来执行此 *** 作(并通过按Delete键确认).为了保持一致,滑动还向tableVC发送setEditing:YES,然后Delete按钮都发送commitEditingStyle:delete消息和setEditing:NO消息.问题是系统要求在这两个消息之间的表中行数,而不是在setEditing:NO之后.因此,它记得还有一行而不是实际的行.然后,如果您对表执行任何 *** 作(例如再次单击“编辑”,再次插入“添加”行),则会看到不一致的行数和崩溃.请参见下面输出中的案例2.

顺便说一句,我认为如果你进行滑动删除会有第二个错误,但是改变主意并点击完成(而不是点击删除以外的任何地方).它再次递归调用setEditing:YES.见输出中的案例3

=============>>CASE 1: Using Edit control to setEditing2013-12-29 11:02:04.032 Recipes[10287:70b] Num Rows: 4 2013-12-29 11:02:04.035 Recipes[10287:70b] Num Rows: 4 -Hit Edit2013-12-29 11:02:14.720 Recipes[10287:70b] setEditing: On2013-12-29 11:02:14.725 Recipes[10287:70b] Inserting Add row 42013-12-29 11:02:14.726 Recipes[10287:70b] Num Rows: 4 +12013-12-29 11:02:14.727 Recipes[10287:70b] ProvIDing Add Cell for row 4-Hit EditControl ("-") then Delete2013-12-29 11:02:21.806 Recipes[10287:70b] Deleting ingredIEnt at row 22013-12-29 11:02:21.808 Recipes[10287:70b] Num Rows: 3 +1-Hit Done2013-12-29 11:02:28.032 Recipes[10287:70b] setEditing: Off2013-12-29 11:02:28.036 Recipes[10287:70b] Deleting Add row 32013-12-29 11:02:28.036 Recipes[10287:70b] Num Rows: 3 CASE 2: Using Swipe to Delete2013-12-29 11:03:21.705 Recipes[10304:70b] Num Rows: 4 2013-12-29 11:03:21.707 Recipes[10304:70b] Num Rows: 4 -Swipe on row 22013-12-29 11:03:34.357 Recipes[10304:70b] setEditing: On2013-12-29 11:03:34.358 Recipes[10304:70b] Inserting Add row 42013-12-29 11:03:34.359 Recipes[10304:70b] Num Rows: 4 +12013-12-29 11:03:34.359 Recipes[10304:70b] ProvIDing Add Cell for row 4-Hit Delete2013-12-29 11:03:38.427 Recipes[10304:70b] Deleting ingredIEnt at row 22013-12-29 11:03:38.431 Recipes[10304:70b] Num Rows: 3 +12013-12-29 11:03:38.432 Recipes[10304:70b] setEditing: Off2013-12-29 11:03:38.434 Recipes[10304:70b] Deleting Add row 3         NOTE THAT IT DOES >>NOT<< CALL numberOfRows during this delete,but complains that current numberOfRows is wrong.2013-12-30 23:54:26.349 Recipes[16694:70b] *** Assertion failure in -[UItableVIEw _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2935.80.1/UItableVIEw.m:13662013-12-30 23:54:26.352 Recipes[16694:70b] *** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'InvalID update: invalID number of rows in section 1.  The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4),plus or minus the number of rows inserted or deleted from that section (1 inserted,0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,0 moved out).'*** First throw call stack:(    0   CoreFoundation                      0x01b48c94 __exceptionPreprocess + 180    1   libobjc.A.dylib                     0x018c78b6 objc_exception_throw + 44    2   CoreFoundation                      0x01b48af8 +[NSException raise:format:arguments:] + 136    3   Foundation                          0x005aa1ae -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116    4   UIKit                               0x00ab3463 -[UItableVIEw _endCellAnimationsWithContext:] + 13402    5   UIKit                               0x00ac313a -[UItableVIEw endUpdatesWithContext:] + 51    6   UIKit                               0x00ac3168 -[UItableVIEw endUpdates] + 41    7   Recipes                             0x00009a8c -[RecipeDetailVIEwController setEditing:animated:] + 908    8   UIKit                               0x00cab0b5 -[UItableVIEwController tableVIEw:willBeginEditingRowAtIndexPath:] + 49    9   UIKit                               0x00abbb39 -[UItableVIEw _senDWillBeginEditingForIndexPath:] + 73    10  UIKit                               0x00ac772d -[UItableVIEw _swipeCellAtPoint:] + 346    11  UIKit                               0x00c44cd0 -[UItableVIEwCellScrollVIEw gestureRecognizerShouldBegin:] + 354    12  UIKit                               0x00d6d676 -[UIGestureRecognizer _shouldBegin] + 1309    13  UIKit                               0x00d69f95 -[UIGestureRecognizer setState:] + 171    14  UIKit                               0x00d9a9d7 -[UIPanGestureRecognizer touchesMoved:withEvent:] + 142    15  UIKit                               0x00e4dd5a -[UIScrollVIEwPanGestureRecognizer touchesMoved:withEvent:] + 89    16  UIKit                               0x00a1c148 -[UIWindow _sendGesturesForEvent:] + 649    17  UIKit                               0x00a1d2e1 -[UIWindow sendEvent:] + 1021    18  UIKit                               0x009eff32 -[UIApplication sendEvent:] + 242    19  UIKit                               0x009d9ec3 _UIApplicationHandleEventQueue + 11455    20  CoreFoundation                      0x01ad1f5f __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15    21  CoreFoundation                      0x01ad18eb __CFRunLoopDoSources0 + 235    22  CoreFoundation                      0x01aee9be __CFRunLoopRun + 910    23  CoreFoundation                      0x01aee1e3 CFRunLoopRunspecific + 467    24  CoreFoundation                      0x01aedffb CFRunLoopRunInMode + 123    25  GraphiCSServices                    0x02f5a2c2 GSEventRunModal + 192    26  GraphiCSServices                    0x02f5a0e9 GSEventRun + 104    27  UIKit                               0x009dcabb UIApplicationMain + 1225    28  Recipes                             0x0000257d main + 125    29  Recipes                             0x000024f5 start + 53)>>CASE 3: Using Swipe to Delete but then not deleting,with "Done"2013-12-29 11:05:20.802 Recipes[10319:70b] Num Rows: 4 2013-12-29 11:05:20.805 Recipes[10319:70b] Num Rows: 4 -Swipe on row 22013-12-29 11:05:25.166 Recipes[10319:70b] setEditing: On2013-12-29 11:05:25.167 Recipes[10319:70b] Inserting Add row 42013-12-29 11:05:25.168 Recipes[10319:70b] Num Rows: 4 +12013-12-29 11:05:25.168 Recipes[10319:70b] ProvIDing Add Cell for row 4-Hit Done2013-12-29 11:05:27.685 Recipes[10319:70b] setEditing: Off2013-12-29 11:05:27.686 Recipes[10319:70b] setEditing: OffBreakpoint at beginning of setEditingAnimated shows:#0  0x00008edb in -[RecipeDetailVIEwController setEditing:animated:] at /Users/hugh/Downloads/iPhoneCoreDataRecipes-2/Classes/RecipeDetailVIEwController.m:150#1  0x00c90f1b in -[UItableVIEwController tableVIEw:dIDEndEditingRowAtIndexPath:] ()#2  0x00aadcbb in -[UItableVIEw _sendDIDEndEditingForIndexPath:] ()#3  0x00ac4a1f in -[UItableVIEw _endSwipetoDeleteRowDIDDelete:] ()#4  0x00abbdbb in -[UItableVIEw _setEditing:animated:forced:] ()#5  0x00abbf58 in -[UItableVIEw setEditing:animated:] ()#6  0x00c90982 in -[UItableVIEwController setEditing:animated:] ()#7  0x00008f16 in -[RecipeDetailVIEwController setEditing:animated:] at /Users/hugh/Downloads/iPhoneCoreDataRecipes-2/Classes/RecipeDetailVIEwController.m:150#8  0x00afc3ae in -[UIVIEwController(UINavigationControllerItem) _toggleEditing:] ()#9  0x01853874 in -[NSObject performSelector:withObject:withObject:] ()#10 0x009d60c2 in -[UIApplication sendAction:to:from:forEvent:] ()#11 0x00caac9b in -[UIbarbuttonItem(UIInternal) _sendAction:withEvent:] ()NOTE THE RECURSIVE CALL TO setEditing:animated:AND CONTINUING LEADS TO THE CRASH:2013-12-29 11:05:27.688 Recipes[10319:70b] Deleting Add row 42013-12-29 11:05:27.689 Recipes[10319:70b] Num Rows: 4 2013-12-29 11:05:27.693 Recipes[10319:70b] Deleting Add row 42013-12-29 11:05:27.694 Recipes[10319:70b] Num Rows: 4 2013-12-29 11:05:27.694 Recipes[10319:70b] *** Assertion failure in -[UItableVIEw _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2903.23/UItableVIEw.m:10762013-12-29 11:05:27.697 Recipes[10319:70b] *** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'attempt to delete row 4 from section 1 which only contains 4 rows before the update'*** First throw call stack:(    0   CoreFoundation                      0x01abe5e4 __exceptionPreprocess + 180    1   libobjc.A.dylib                     0x018418b6 objc_exception_throw + 44    2   CoreFoundation                      0x01abe448 +[NSException raise:format:arguments:] + 136    3   Foundation                          0x005a3fee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116    4   UIKit                               0x00aa3373 -[UItableVIEw _endCellAnimationsWithContext:] + 3952    5   UIKit                               0x00ab4caa -[UItableVIEw endUpdatesWithContext:] + 51    6   UIKit                               0x00ab4cd8 -[UItableVIEw endUpdates] + 41    7   Recipes                             0x000091fc -[RecipeDetailVIEwController setEditing:animated:] + 908    8   UIKit                               0x00afc3ae -[UIVIEwController(UINavigationControllerItem) _toggleEditing:] + 73    9   libobjc.A.dylib                     0x01853874 -[NSObject performSelector:withObject:withObject:] + 77    10  UIKit                               0x009d60c2 -[UIApplication sendAction:to:from:forEvent:] + 108    11  UIKit                               0x00caac9b -[UIbarbuttonItem(UIInternal) _sendAction:withEvent:] + 139    12  libobjc.A.dylib                     0x01853874 -[NSObject performSelector:withObject:withObject:] + 77    13  UIKit                               0x009d60c2 -[UIApplication sendAction:to:from:forEvent:] + 108    14  UIKit                               0x009d604e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61    15  UIKit                               0x00ace0c1 -[UIControl sendAction:to:forEvent:] + 66    16  UIKit                               0x00ace484 -[UIControl _sendActionsForEvents:withEvent:] + 577    17  UIKit                               0x00acd733 -[UIControl touchesEnded:withEvent:] + 641    18  UIKit                               0x00a1351d -[UIWindow _sendtouchesForEvent:] + 852    19  UIKit                               0x00a14184 -[UIWindow sendEvent:] + 1232    20  UIKit                               0x009e7e86 -[UIApplication sendEvent:] + 242    21  UIKit                               0x009d218f _UIApplicationHandleEventQueue + 11421    22  CoreFoundation                      0x01a4783f __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15    23  CoreFoundation                      0x01a471cb __CFRunLoopDoSources0 + 235    24  CoreFoundation                      0x01a6429e __CFRunLoopRun + 910    25  CoreFoundation                      0x01a63ac3 CFRunLoopRunspecific + 467    26  CoreFoundation                      0x01a638db CFRunLoopRunInMode + 123    27  GraphiCSServices                    0x02eae9e2 GSEventRunModal + 192    28  GraphiCSServices                    0x02eae809 GSEventRun + 104    29  UIKit                               0x009d4d3b UIApplicationMain + 1225    30  Recipes                             0x00001ced main + 125    31  Recipes                             0x00001c65 start + 53
解决方法 我还不确定这是否是CoreDataRecipes程序的错误或iOS 7中的错误,
但以下似乎有效:

在tableVIEw:commitEditingStyle:editingStyle:forRowAtIndexPath:中,在swipe-to-delete的情况下,我们知道’self.editing’此时为NO,所以如果你在deleteRows之后添加一个Hack调用’self.editing’,tableVIEw似乎更新了它的内部numberOfRows.具体来说,之后:

[self.tableVIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UItableVIEwRowAnimationtop];

加:

if (!self.editing) self.editing = NO;

其次,在setEditing:animated:中,在删除之前检查附加的“Add Item”行是否实际存在.具体来说,替换:

} else {        [self.tableVIEw deleteRowsAtIndexPaths:ingredIEntsInsertIndexPath withRowAnimation:UItableVIEwRowAnimationtop];        overvIEwTextFIEld.placeholder = @"";    }

有:

} else {        if (ingredIEntsCount < [self.tableVIEw numberOfRowsInSection:INGREDIENTS_SECTION]) {            [self.tableVIEw deleteRowsAtIndexPaths:ingredIEntsInsertIndexPath withRowAnimation:UItableVIEwRowAnimationtop];        }        overvIEwTextFIEld.placeholder = @"";    }

这似乎解决了你的两个问题.

@H_419_2@ 总结

以上是内存溢出为你收集整理的为什么在iOS 7下刷卡到删除会崩溃?全部内容,希望文章能够帮你解决为什么在iOS 7下刷卡到删除会崩溃?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1040184.html

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

发表评论

登录后才能评论

评论列表(0条)

保存