iOS / Swift:tableView cellForRowAtIndexPath崩溃

时间:2016-04-17 00:03:03

标签: ios swift uitableview

我遇到第389行的EXC_BREAKPOINT崩溃

import numpy as np
import matplotlib.dates as mdates
from matplotlib import pyplot as plt

date_decode_function = lambda b: mdates.strpdate2num('%d/%m/%Y')(b.decode())

dates, growth_rates = np.genfromtxt('growth_rate.csv',
                                    delimiter = ',',
                                    unpack=True,
                                    converters = {0: date_decode_function})


fig, ax = plt.subplots()
ax.plot_date(dates, growth_rates,'-',lw=2)
plt.xlabel("Date", fontsize=16)
plt.ylabel("Growth rate", fontsize=16)

plt.grid()
plt.show()

这是来自Crashlytics的崩溃报告,发生率为2%的用户:

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 }

知道为什么会这样吗?

3 个答案:

答案 0 :(得分:4)

崩溃是由于suggestionStations数组没有索引值。

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

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

答案 1 :(得分:1)

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

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

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

答案 2 :(得分:0)

确保您已将您的小区标识符设置为&#34; StationsCell&#34;在 TreeSet<String> set = new TreeSet<>( Arrays.asList("a", "z", "b", "y")); String cur; cur = set.first(); // a cur = set.higher(cur); // b cur = set.higher(cur); // y cur = set.higher(cur); // z cur = set.lower(cur); // y cur = set.lower(cur); // b cur = set.lower(cur); // a cur = set.lower(cur); // null 中。选择Cell并转到Attributes Inspector。

同样在函数之前添加Main.Storyboard,因此它应该是override