Я пытаюсь обновить значение label.text в строке таблицы. Предполагается, что обновление запускается пользователем, вводящим число в другое текстовое поле в этой строке:
Мой код выглядит так:
Swift 3: ViewController
import UIKit
class RiskPlan: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var probability1 = String()
var impact1 = String()
var riskFactor = String()
var result = Int()
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView!.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CellCustomized
impact1 = (cell.impact?.text)!
probability1 = (cell.probability?.text)!
result = Int(impact1)! * Int(probability1)!
cell.riskFactor?.text = String(result)
self.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.top)
return cell
}
}
Swift 3: CellCustomized
import UIKit
class CellCustomized: UITableViewCell {
@IBOutlet weak var probability: UITextField!
@IBOutlet weak var impact: UITextField!
@IBOutlet weak var riskFactor: UILabel!
}
Моя проблема в том, что
self.tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.top)
не выполняет обновление и- Я получаю «фатальную ошибку: неожиданно найдено nil при развертывании необязательного значения» для
result = Int(impact1)! * Int(probability1)!