我在第 389 行遇到 EXC_BREAKPOINT 崩溃
386 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
387 let cell = tableView.dequeueReusableCellWithIdentifier("StationsCell", forIndexPath: indexPath)
388 cell.textLabel?.text = self.suggestionStations?[indexPath.row]
389 return cell
390 }
这是 Crashlytics 的崩溃报告,发生在 2% 的用户身上:
线程:崩溃:com.apple.main-thread
0 Trenìt! 0x10004a2e4 专用 MasterViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (MasterViewController.swift:389)
1 Trenìt! 0x100046488 @objc MasterViewController.tableView(UITableView, cellForRowAtIndexPath : NSIndexPath) -> UITableViewCell (MasterViewController.swift)
2 UIKit 0x18c6b239c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 544
3 UIKit 0x18c6a6fc4 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
4 UIKit 0x18c49cc60 -[UITableView layoutSubviews] + 172
5 UIKit 0x18c3b9874 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
6 QuartzCore 0x18bd11d58 -[CALayer layoutSublayers] + 168
7 QuartzCore 0x18bd0c944 CA::Layer::layout_if_needed(CA::Transaction*) + 320
知道为什么会这样吗?
最佳答案
崩溃是由 suggestionStations
数组在索引处没有值引起的。
当数组重置为 0 时,我没有在表上调用 ReloadData()
。因此当索引处的值不存在时,表函数仍然在竞争条件下被调用不再。
解决方法是在重置数组后也调用 ReloadData()。否则可能会检查是否为数组定义了索引,但如果每次都正确调用 reloadData,则不需要检查。
关于iOS/swift : tableView cellForRowAtIndexPath crash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671222/