2017-09-14 18 views
0

我知道这可能是一个noob问题,但我怎样才能从另一个视图控制器的表视图插入数据?这里是我的代码:如何将数据插入到另一个视图控制器的tableView中?

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年9月14日22: 09:29.011455 + 0300 Parkovka![504:47018]致命错误:意外发现零而展开的可选值 (LLDB)

+0

调用FUNC在viewDidLoad中添加你所得到的控制台错误让我们能够帮助您更好地 –

+0

只是一个提示,定义变量时使用较低的骆驼盒防止与类型混淆。 –

+0

感谢您的建议。编码非常新颖。 –

回答

0

你可以使用这个this.Add代码添加到您的ViewController

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let destination = segue.destination as? "YOURNAMETABLEVIEWCONTROLLER" { 
     destination.time = "\(self.LocationAndTimeData.getTextDate())" 
    } 
} 

添加属性时您的tableView控制器和tableViewController

addData(Time: time) 
相关问题