我有两个视图控制器,一个有3个表视图,另一个控制器,我有一个uitextfield和在文本字段中输入的文本,我想把它添加到另一个视图控制器的一个名为ScheduleTableView的表视图中。以下是我的代码,但在vc.ScheduleTableView.beginUpdates()
处展开可选值时,我收到错误:意外发现nil
@IBAction func addButtonTapped(_ sender: YTRoundedButton) {
self.performSegue(withIdentifier: "secondvc", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "secondvc" {
print(TitleTextField.text!)
let vc = segue.destination as! GrowthMainViewController
vc.ScheduleArray.append(TitleTextField.text!)
let indexPath = IndexPath(row: vc.ScheduleArray.count - 1, section: 0)
vc.ScheduleTableView.beginUpdates()
vc.ScheduleTableView.insertRows(at: [indexPath], with: .automatic)
vc.ScheduleTableView.reloadData()
vc.ScheduleTableView.endUpdates()
TitleTextField.text = ""
view.endEditing(true)
}
}
https://stackoverflow.com/questions/50588090
复制相似问题