繁体   English   中英

iOS / Swift:tableView cellForRowAtIndexPath崩溃

[英]iOS/Swift: tableView cellForRowAtIndexPath crash

我遇到了第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数组在索引处没有值而引起的。

当数组重置为0时,我没有在表上调用ReloadData() 。因此,当索引处的值不再存在时,表函数仍然在竞争条件中被调用。

修复是在重置数组后调用ReloadData()。 否则可能会检查是否为数组定义了索引,但如果每次都正确调用reloadData,则不需要这样做。

我们遇到了同样的问题。 此问题在iOS 10 beta1上100%可重现。

虽然很难相信,但我们设法通过在故事板上提供一个非常短的单元格标识符来解决问题。 就像“PhoneContactCell”重命名为“PCell”一样。

经过一些调查,我们认为这是一个故事板错误:如果复制和修改单元格原型,那么它可能会有这个问题。

确保您已将主要标识符设置为Main.Storyboard “StationsCell”。 选择Cell并转到Attributes Inspector。

还要在函数之前添加override ,因此它应该override func

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM