我有一个嵌入到名为 UserDashboardVC 的 VC 中的导航 Controller 。然后我有一个菜单 VC,一个选项打开另一个带有表格 View 的 VC,ManageAccountVC。当我选择表格行时,我希望它展开并填充 UserDashboardVC 上的数据。
我正在努力使用来自 ManageAccountVC 的 unwind segue 将数据传递回 UserDashboardVC。
在我的 UserDashboardVC (root) 中,我有我的 unwind segue 代码:
@IBAction func unwindUserDashboardVC(_ unwindSegue: UIStoryboardSegue) {
userCompanyLabel.text = PassCompanyOffice}
在我的 ManageAccountVC 中,tableview 单元格已连接到 Exit unwindUserDashboardVC,当我单击单元格时,我将其展开到 UserDashboardVC。我在 ManageAccountVC 中有一个函数来选择行:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
PassCompanyOffice = userAccountArray[indexPath.row].companyOffice!
}
我在 ManageAccountVC 中也有 Prepare 函数,它似乎在我获得行值之前触发:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let ConfirmVC = segue.destination as! UserDashboardVC
ConfirmVC.PassCompanyOffice = PassCompanyOffice
}
为什么我的 unwind segue 在我的单元格行被识别之前被执行?如何传回我的数据?
最佳答案
您可能希望创建一个类成员来保存选定的行并在 willSelectRow 中为 tableview 分配它。在这种情况下,然后在为 Segue 或 unwind segue 准备中获取值。在 unwind segue 中放置一个断点以确定所选行变量的状态,然后再使用它。
手动转场
要将单元格单击操作与 segue 分开,您需要删除从 tableview 单元格到导出的退出 segue。
然后创建从 View Controller 到退出图标的手动转场。给那个segue一个标识符,然后用标识符调用performSegue(使用exitSegueIdentifier)
这样你就可以将这两个 Action 分开。您可以在不退出的情况下单击表格。在您的代码库中,您可以决定何时调用 performSegue 并使用手动退出 segue 实际关闭 VC。
关于ios - 在传递数据之前在 tableview 中丢失行 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58118872/