=> Demo Project @ GitHub <=dequeueReusableCellWithIdentifier索引超出結合
我有一個UITableViewController
具有TableView
在我所具有另一TableView
在它的細胞。
當該內部TableView
試圖dequeueReusableCellWithIdentifier
爲indexPath (1,0)
應用程序崩潰與
Terminating app due to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
雖然該內部TableView
顯然有3個部分。堆棧跟蹤之中:
-[__NSArrayI objectAtIndex:] + 190
-[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 61
-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1711
+[UIView(Animation) performWithoutAnimation:] + 65
-[UITableView _configureCellForDisplay:forIndexPath:] + 312
-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 271
因爲微量的,我試圖實現
override func tableView(tableView: UITableView,
indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int {
return 0
}
但隨後的應用程序崩潰的
-[UITableViewDataSource tableView:viewForFooterInSection:]
與同index 1 beyond bounds [0 .. 0]
...
實現是相對無關恕我直言,但它是
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if tableView.tag == 0 {
return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
}
if let cell = tableView.dequeueReusableCellWithIdentifier("cell") as? UITableViewCell {
return cell
}
return UITableViewCell() // Shouldn't happen.
}
我不會爲那最後一行感到驕傲:)但你還會做什麼來取悅編譯器?我從來沒有達到過這條線。崩潰很明顯發生在內部TableView
其中tag
爲1.
你可以發佈完整的方法嗎? – Amit89
你的'tableView:cellForRowAtIndexPath:'方法的實現是什麼? –
@Amit89 @madboy我添加了我的'cellForRowAtIndexPath'實現,儘管在這種情況下我覺得這並不重要。就像我說的那樣,它在'出列'上崩潰。 –