<分区>
我在重新加载 tableView 时遇到问题,这是我拥有的那批代码:
func updateIncomingData () {
print ("Received String:")
print (receivedDataString)
print("Clearing TNU Array")
TNUArray.removeAll()
temperatureReadingArray = receivedDataString.components(separatedBy: " ")
print("temperatureReadingArray is:")
print(temperatureReadingArray)
self.temperatureReadingsTable.reloadData()
calculateTNU()
}
func calculateTNU()
{
var TNU: Double = 0.000
print("TNU Array:")
print(TNUArray)
let minValue = TNUArray.min()
print("Values MIN/MAX are:")
print(minValue ?? "nil")
let maxValue = TNUArray.max()
print(maxValue ?? "nil")
if (minValue != nil && maxValue != nil)
{
TNU = maxValue! - minValue!
calculatedTNU = String(format:"%.3f", TNU)
TNULabel.text = calculatedTNU
}
else
{
print("Max or Min had nil values")
}
}
现在,在这里您可以看到我在调用 calculateTNU() 之前调用了 reloadData()。这调用了表加载函数,对这个函数特别感兴趣:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: temperatureReading) as! TemperatureReading
cell.channelLabel.text = channelNames[indexPath.row]
cell.readingLabel.text = temperatureReadingArray[indexPath.row]
if (channelNames.count == 1)
{
cell.toggleSwitch.isHidden = true
}
if (cell.toggleSwitch.isOn)
{
if let value = Double(cell.readingLabel.text!)
{
print("valid number, appending")
TNUArray.append(value)
}
else
{
print("Not a valid number reading")
}
}
return cell
}
现在,问题是它在完成重新加载数据之前运行 calculateTNU(),这导致我的 calculateTNU() 函数没有任何可读取的值(因为当表格正在填充时,它也会填充所需的数组用于 TNU 计算)。
在执行下一个命令功能之前是否有“等待重新加载”?