我想在TableViewController和ViewController之间传递数据 程序不进入方法 我的快速代码:
override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
let destView : ViewController = unwindSegue.destination as! ViewController
destView.min = Int(minTable)
destView.tableText = unitsText
}
我获取数据:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let tableCell = moneyArray[indexPath.row]
minTable = tableCell.val
unitsText = tableCell.name
let _ = navigationController?.popViewController(animated: true)
}
添加我的表代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath) as! TableViewCell
let tableShow = moneyArray[indexPath.row]
cell.nameCurrency?.text = tableShow.name
cell.valueCarrency?.text = "\(tableShow.val)"
return cell
}
最佳答案
您在 didSelectRow 上使用 popViewController,这意味着您将返回导航 Controller ,而不是推送展开转场或任何转场,因此您无法使用prepareForSegue/unwind 方法。
解决此问题的一个正确方法是使用委托(delegate)。
您可以在这里找到更多相关信息: Passing data back from view controllers Xcode
但是如果你想使用 unwind segue,你必须在前一个 viewController 上编写你的 unwind 方法,而不是当前的 viewController。此外,您还需要使用带有展开转场标识符的 PerformSegue 方法。
您可以在此处查看有关展开转场的更多信息: What are Unwind segues for and how do you use them?
关于ios - 在 Swift 中的 Controller 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41209776/