我在第 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% 的用户身上:
Thread : Crashed: com.apple.main-thread
0 Trenìt! 0x10004a2e4 specialized 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
数组的索引处没有值。
我没有打电话ReloadData()
当数组重置为 0 时,在表上。因此,当索引处的值不再存在时,表函数仍会在竞争条件下被调用。
修复方法是在重置数组后也调用 ReloadData()。否则,可能会检查是否为数组定义了索引,但如果每次都正确调用 reloadData,则不需要这样做。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)