如何从另一个视图控制器插入数据视图中



我知道这可能是一个菜鸟问题,但是如何从另一个视图控制器中插入数据视图中?这是我的代码:

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()
  }

请帮助:/

这是控制台消息:

致命错误:未包装可选值时出乎意料的发现2017-09-14 22:09:29.011455 0300 Parkovka![504:47018]致命错误:意外地发现了无需可选值(LLDB)

您可以使用此代码到您的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)

最新更新