我知道这可能是一个noob问题,但是如何将数据从另一个View Controller插入到表视图中?这是我的代码:
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
var needToSegue = false
switch result {
case .cancelled:
print("Mail cancelled")
case .saved:
print("Mail saved")
case .sent:
needToSegue = true
print("Mail sent")
case .failed:
print("Mail sent failure: \(error?.localizedDescription ?? "nil")")
}
controller.dismiss(animated: true) {
if needToSegue {
self.AllListOfViolations.addData(Time: "\(self.LocationAndTimeData.getTextDate())")
self.performSegue(withIdentifier: "AllList", sender: self)
}
}
}
我需要在AllList tableView中插入时间,但不幸的是,这不起作用。这是我的addData函数:
func addData(Time: String) {
violationType.append(Time)
// Update Table Data
tableView.beginUpdates()
tableView.insertRows(at: [IndexPath(row: violationType.count-1, section: 0)], with: .automatic)
tableView.endUpdates()
}
请帮忙:/
以下是控制台消息:
致命错误:在展开Optional值时意外发现nil 2017-09-14 22:09:29.011455 + 0300 Parkovka![504:47018]致命错误:在展开可选值时意外发现nil (lldb)
答案 0 :(得分:0)
您可以使用此功能。将此代码添加到ViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? "YOURNAMETABLEVIEWCONTROLLER" {
destination.time = "\(self.LocationAndTimeData.getTextDate())"
}
}
向tableView控制器添加属性时间,并在tableViewController中的viewDidLoad中调用func
addData(Time: time)