1
我只需要添加一個細胞&得到EXC_CRASHContiguousArrayStorage行無法識別的選擇發送到實例
tableView.beginUpdates()
tableView.insertRowsAtIndexPaths([indexPathToAdd], withRowAnimation: .Automatic)
expanded = true
accordionIndex = newAccordionIndex
tableView.endUpdates()
數據源代表
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return scheme.numberOfCells
}
var numberOfCells: Int {
let count = rowCountHandler!()
return expanded ? count + 1 : count
}
調試後,誤差在tableView.endUpdates() 這很奇怪因爲如果單元格已經存在&我刪除它&將它添加到新的indexPath,tableView.endUpdates()沒有問題。
完整的方法
func handleDoubleTap(tableView: UITableView, withAbsoluteIndex index: Int) {
if !expanded {
// Add a cell below the double tapped cell
let newAccordionIndex = index + 1
let indexPathToAdd = [NSIndexPath(forRow: newAccordionIndex, inSection: 0)]
//expanded = true
//accordionIndex = newAccordionIndex
//tableView.reloadData()
tableView.beginUpdates()
tableView.insertRowsAtIndexPaths([indexPathToAdd], withRowAnimation: .Automatic)
expanded = true
accordionIndex = newAccordionIndex
tableView.endUpdates()
} else {
if index == parentIndex { return }
// Remove the current accordion cell & add a new one
// below the double tapped cell
let indexPathToRemove = NSIndexPath(forRow: accordionIndex, inSection: 0)
let newAccordionIndex = index > accordionIndex ? index : index + 1
let indexPathToAdd = NSIndexPath(forRow: newAccordionIndex, inSection: 0)
tableView.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPathToRemove], withRowAnimation: .Automatic)
tableView.insertRowsAtIndexPaths([indexPathToAdd], withRowAnimation: .Automatic)
accordionIndex = newAccordionIndex
tableView.endUpdates()
}
}
而且我找不到在那裏我呼籲數組實例行。我猜是某種陣列。
堆棧跟蹤低於
2014-10-07 02:01:10.426 HopperBus[37542:9390828] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtCSs23_ContiguousArrayStorage000000007A8CFA98 row]: unrecognized selector sent to instance 0x7a84d3d0'
*** First throw call stack:
(
0 CoreFoundation 0x004fcdf6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x025b4a97 objc_exception_throw + 44
2 CoreFoundation 0x00504a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x0044d9c7 ___forwarding___ + 1047
4 CoreFoundation 0x0044d58e _CF_forwarding_prep_0 + 14
5 UIKit 0x01789afc -[UIUpdateItem isSectionOperation] + 52
6 UIKit 0x014c011f -[UITableView _endCellAnimationsWithContext:] + 5778
7 UIKit 0x014d771f -[UITableView endUpdatesWithContext:] + 51
8 UIKit 0x014d774d -[UITableView endUpdates] + 41
9 HopperBus 0x001440a1 _TFC9HopperBus17HBAccordionScheme15handleDoubleTapfS0_FTCSo11UITableView17withAbsoluteIndexSi_T_ + 993
10 HopperBus 0x0012dd2f _TFC9HopperBus19RouteViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 319
11 HopperBus 0x0012ddd5 _TToFC9HopperBus19RouteViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 101
12 UIKit 0x014d94fc -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1559
13 UIKit 0x014d96a7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 285
14 UIKit 0x014de9a3 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
15 UIKit 0x013f362e ___afterCACommitHandler_block_invoke + 15
16 UIKit 0x013f35d9 _applyBlockToCFArrayCopiedToStack + 415
17 UIKit 0x013f33ee _afterCACommitHandler + 545
18 CoreFoundation 0x0041ffbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
19 CoreFoundation 0x0041ff00 __CFRunLoopDoObservers + 400
20 CoreFoundation 0x0041593a __CFRunLoopRun + 1226
21 CoreFoundation 0x004151ab CFRunLoopRunSpecific + 443
22 CoreFoundation 0x00414fdb CFRunLoopRunInMode + 123
23 GraphicsServices 0x06b0e24f GSEventRunModal + 192
24 GraphicsServices 0x06b0e08c GSEventRun + 104
25 UIKit 0x013c9e16 UIApplicationMain + 1526
26 HopperBus 0x000d44fe top_level_code + 78
27 HopperBus 0x000d453b main + 43
28 libdyld.dylib 0x02d18ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
的測試,你能告訴更多的你'UITableViewDataSource'代碼
[NSIndexPath]
可以轉換爲[AnyObject]
所以[[NSIndexPath]]
它沒有抓住它?我的直覺是你添加了一個表格行,但沒有從'tableView(_:numberOfRowsInSection:)'返回正確的值。 – 2014-10-07 01:28:50如何定義'indexPathToAdd'? – 2014-10-07 03:40:31
請注意'let indexPathToAdd = [NSIndexPath(forRow:newAccordionIndex,inSection:0)]'so'[indexPathToAdd]'是一個數組的數組。可悲的是,類型檢查沒有捕獲:( 感謝您的幫助 – 2014-10-07 04:28:58