iOS / Swift:tableView cellForRowAtIndexPath崩溃 [英] iOS/Swift: tableView cellForRowAtIndexPath crash

查看:1138
本文介绍了iOS / Swift:tableView cellForRowAtIndexPath崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到第389行的EXC_BREAKPOINT崩溃

I am experiencing a EXC_BREAKPOINT crash at line 389

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%的用户:

here is the crash report from Crashlytics, happening at 2% of users:

线程:崩溃:com.apple.main-thread
0Trenìt! 0x10004a2e4专门的MasterViewController.tableView(UITableView,cellForRowAtIndexPath:NSIndexPath) - > UITableViewCell(MasterViewController.swift:389)
1Trenì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 数组引起的,该数组在索引处没有值。

The crash was caused by the suggestionStations array not having a value at the index.

当数组重置为0时,我没有在表上调用 ReloadData()。所以表f当索引的值不再存在时,仍会在竞争条件中调用unction。

I was not calling ReloadData() on the table when the array was reset to 0. So the the table function was still called in a race condition when the value at the index didn't exist anymore.

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

The fix was to call ReloadData() also after resetting the array. Otherwise there could have been a check that the index was defined for the array, but this shouldn't be needed if reloadData is properly called each time.

这篇关于iOS / Swift:tableView cellForRowAtIndexPath崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆