HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么在iOS 7下刷卡到删除会崩溃?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在刷卡到删除后开始收到崩溃报告,并且能够重新创建它.然后因为我使用了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 setEdiTing
2013-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 Edit
2013-12-29 11:02:14.720 Recipes[10287:70b] setEdiTing: On
2013-12-29 11:02:14.725 Recipes[10287:70b] InserTing Add row 4
2013-12-29 11:02:14.726 Recipes[10287:70b] Num Rows: 4 +1
2013-12-29 11:02:14.727 Recipes[10287:70b] Providing Add Cell for row 4
-Hit EditControl ("-") then delete
2013-12-29 11:02:21.806 Recipes[10287:70b] deleting ingredient at row 2
2013-12-29 11:02:21.808 Recipes[10287:70b] Num Rows: 3 +1
-Hit Done
2013-12-29 11:02:28.032 Recipes[10287:70b] setEdiTing: Off
2013-12-29 11:02:28.036 Recipes[10287:70b] deleting Add row 3
2013-12-29 11:02:28.036 Recipes[10287:70b] Num Rows: 3 

CASE 2: Using Swipe to delete
2013-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 2
2013-12-29 11:03:34.357 Recipes[10304:70b] setEdiTing: On
2013-12-29 11:03:34.358 Recipes[10304:70b] InserTing Add row 4
2013-12-29 11:03:34.359 Recipes[10304:70b] Num Rows: 4 +1
2013-12-29 11:03:34.359 Recipes[10304:70b] Providing Add Cell for row 4
-Hit delete
2013-12-29 11:03:38.427 Recipes[10304:70b] deleting ingredient at row 2
2013-12-29 11:03:38.431 Recipes[10304:70b] Num Rows: 3 +1
2013-12-29 11:03:38.432 Recipes[10304:70b] setEdiTing: Off
2013-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:1366
2013-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.  @R_772_3244@ of rows contained in an exisTing section after the update (4) must be equal to @R_772_3244@ of rows contained in that section before the update (4),plus or minus @R_772_3244@ of rows inserted or deleted from that section (1 inserted,0 deleted) and plus or minus @R_772_3244@ 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 2
2013-12-29 11:05:25.166 Recipes[10319:70b] setEdiTing: On
2013-12-29 11:05:25.167 Recipes[10319:70b] InserTing Add row 4
2013-12-29 11:05:25.168 Recipes[10319:70b] Num Rows: 4 +1
2013-12-29 11:05:25.168 Recipes[10319:70b] Providing Add Cell for row 4
-Hit Done
2013-12-29 11:05:27.685 Recipes[10319:70b] setEdiTing: Off
2013-12-29 11:05:27.686 Recipes[10319:70b] setEdiTing: Off
Breakpoint 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 4
2013-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 4
2013-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:1076
2013-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:@R_115_10586@rget: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 = @"";
    }

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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。