gpt4 book ai didi

ios - 使用 Swift 3 将数据从 Modal Viewcontroller 传递到 rootController(不要 Segue)

转载 作者:行者123 更新时间:2023-11-28 08:11:02 29 4
gpt4 key购买 nike

我有一个问题。

我需要帮助。我一直在寻找解决方案大约 5 个小时。不幸的是没有成功。

我的问题是我有几个 Storyboard并且没有使用 Segue 创建。

我希望将选定的 Tableviewcell 标题传递给 rootViewController。

这是我在 ModalViewTable 中的代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let indexNumber = "\(indexPath.row)"

let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRow(at: indexPath!) as UITableViewCell!
let storyboard = UIStoryboard(name: "addTime", bundle: nil)
var viewController = storyboard.instantiateViewController(withIdentifier: "addTimeVC") as! addTimeViewController
viewController.test = "TESTABCDEF"
passedValue = ("\(indexNumber)")
dismiss(animated: true, completion: nil)
}

我的 firstViewController 中有一个属性 test。这里有什么问题?我也尝试过委托(delegate)和闭包,但没有成功。请帮我。

最佳答案

试试这个:

let indexNumber = "\(indexPath.row)"
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRow(at: indexPath!) as UITableViewCell!

let viewController = navigationController!.presentingViewController as! addTimeViewController
viewController.test = "TESTABCDEF"
passedValue = ("\(indexNumber)")
navigationController!.dismiss(animated: true, completion: nil)

当您使用 present(_:animated) 方法以模态方式呈现 View Controller 时,呈现 的 View Controller 具有 presentingViewController属性设置为呈现它的 View Controller 。换句话说,此属性包含对先前 View Controller 的引用。

关于ios - 使用 Swift 3 将数据从 Modal Viewcontroller 传递到 rootController(不要 Segue),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43792315/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com