我的应用程序在强制升级到Swift 2.x之前工作正常。我的下面的代码是在IBAction上执行的,用于按下"崩溃"细胞,例如它用另一个布局替换它然后尝试重新加载单元格,由于各种原因,我被迫将每个单元格包含在它自己的部分中(因此,我可以扩展地重新加载该部分)。我已经尝试将各种变量输出到终端;输入是合理的。我还尝试在.beginUpdates()和.endUpdates()中包装它,当在调试器中遍历它时,它只会在.endUpdates()调用而不是.reloadSections()调用上抛出以下异常。 。我也尝试用.reloadData()覆盖调用替换.reloadSections(),我收到相同的堆栈跟踪,让我相信它在某种程度上是TableView对象的内部。
// Set Selected Patient Configuration to "Collapsed"
patientList.patients[ sender.tag ].updateConfiguration( collapsedConfiguration )
let animation = UITableViewRowAnimation.Automatic
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
我的代码将评估支持数据的折叠状态,并在完整或折叠视图中绘制。
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x00e2fa84 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03235e02 objc_exception_throw + 50
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
9 libobjc.A.dylib 0x0324a00c -[NSObject performSelector:] + 62
10 CoreFoundation 0x00d60571 -[NSArray makeObjectsPerformSelector:] + 273
11 UIKit 0x021b06f6 -[UINib instantiateWithOwner:options:] + 2102
12 UIKit 0x01eeed6c -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 457
13 UIKit 0x01eef173 -[UITableView dequeueReusableCellWithIdentifier:] + 48
14 Halo 0x001b5174 _TFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2356
15 Halo 0x001be459 _TToFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 89
16 UIKit 0x01f03a19 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
17 UIKit 0x01f03b47 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
18 UIKit 0x022568cc -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 8353
19 UIKit 0x0226181a -[_UITableViewUpdateSupport _setupAnimations] + 161
20 UIKit 0x01ed7fd3 -[UITableView _updateWithItems:updateSupport:] + 3653
21 UIKit 0x01ecfc91 -[UITableView _endCellAnimationsWithContext:] + 17491
22 UIKit 0x01eea538 -[UITableView _updateSections:updateAction:withRowAnimation:headerFooterOnly:] + 460
23 UIKit 0x01eea625 -[UITableView reloadSections:withRowAnimation:] + 73
24 Halo 0x00105e10 _TFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 6208
25 Halo 0x0010645d _TToFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 61
26 libobjc.A.dylib 0x0324a0b5 -[NSObject performSelector:withObject:withObject:] + 84
27 UIKit 0x01d8016a -[UIApplication sendAction:to:from:forEvent:] + 118
28 UIKit 0x01d800e9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
29 UIKit 0x01f1e19f -[UIControl sendAction:to:forEvent:] + 79
30 UIKit 0x01f1e51f -[UIControl _sendActionsForEvents:withEvent:] + 408
31 UIKit 0x01f1d525 -[UIControl touchesEnded:withEvent:] + 714
32 UIKit 0x022efeaa _UIGestureRecognizerUpdate + 12763
33 UIKit 0x01dfabdf -[UIWindow _sendGesturesForEvent:] + 1559
34 UIKit 0x01dfc298 -[UIWindow sendEvent:] + 1137
35 UIKit 0x01da1efb -[UIApplication sendEvent:] + 266
36 UIKit 0x01d77cb6 _UIApplicationHandleEventQueue + 7802
37 CoreFoundation 0x00d49d1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
38 CoreFoundation 0x00d3f9ab __CFRunLoopDoSources0 + 523
39 CoreFoundation 0x00d3edc8 __CFRunLoopRun + 1032
40 CoreFoundation 0x00d3e706 CFRunLoopRunSpecific + 470
41 CoreFoundation 0x00d3e51b CFRunLoopRunInMode + 123
42 GraphicsServices 0x058c0664 GSEventRunModal + 192
43 GraphicsServices 0x058c04a1 GSEventRun + 104
44 UIKit 0x01d7e1eb UIApplicationMain + 160
45 Halo 0x0011eb6c main + 140
46 libdyld.dylib 0x03ceca21 start + 1
47 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
堆栈对我没有多大帮助,我甚至无法找出开始消息:" insertObject:atIndex:]:index 2超出bounds [0 .. 0]。"没有这个样本中的哪个地方以及我对单个表条目的测试应该有一个' 2的索引。'您可以提供任何帮助。
这是我的''在这个例外:
* thread #1: tid = 0xc9ca7, 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x03fe4634 libsystem_pthread.dylib`pthread_kill + 101
frame #2: 0x03d9339d libsystem_c.dylib`abort + 156
frame #3: 0x04034ae7 libc++abi.dylib`abort_message + 151
frame #4: 0x04055683 libc++abi.dylib`default_terminate_handler() + 300
frame #5: 0x032360b6 libobjc.A.dylib`_objc_terminate() + 108
frame #6: 0x04052d0d libc++abi.dylib`std::__terminate(void (*)()) + 14
frame #7: 0x0405293e libc++abi.dylib`__cxa_rethrow + 103
frame #8: 0x03235fad libobjc.A.dylib`objc_exception_rethrow + 47
frame #9: 0x00d3e7d0 CoreFoundation`CFRunLoopRunSpecific + 672
frame #10: 0x00d3e51b CoreFoundation`CFRunLoopRunInMode + 123
frame #11: 0x058c0664 GraphicsServices`GSEventRunModal + 192
frame #12: 0x058c04a1 GraphicsServices`GSEventRun + 104
frame #13: 0x01d7e1eb UIKit`UIApplicationMain + 160
* frame #14: 0x0011eb6c Halo`main + 140 at AppDelegate.swift:26
frame #15: 0x03ceca21 libdyld.dylib`start + 1
根据请求,输出后面是代码:
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Test Output
print( "tableView.numberOfSections: \(tableView.numberOfSections)" )
print( "tableView.numberOfRowsInSection( sender.tag ): \(tableView.numberOfRowsInSection( sender.tag ))" )
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
tableView.numberOfSections: 1
tableView.numberOfRowsInSection( sender.tag ): 1
答案 0 :(得分:1)
堆栈跟踪的这一部分(可能)意味着你有IBOutletCollection
,而UIKit现在正试图从故事板或笔尖填充它:
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
此部分看起来正在尝试将绑定对象添加到现有数组中:
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
所有这些意味着错误可能与您发布的代码无关,而是与您的笔尖以及它与其绑定的属性的交互方式有关。
看看你是否正在使用IBOutletCollection
,如果是,请开始调试它所绑定的内容。