需要通过以下方式将值从一个视图控制器添加到另一视图控制器。我能够成功移动到另一个页面,但无法传递值
sideMenuController?.cache(viewControllerGenerator: {
self.storyboard?.instantiateViewController(withIdentifier: "projectDetailController")
}, with: "333")
sideMenuController?.delegate = self as? SideMenuControllerDelegate
sideMenuController?.setContentViewController(with: "333", animated: Preferences.shared.enableTransitionAnimation)
sideMenuController?.hideMenu()
答案 0 :(得分:2)
在ProjectDetailController
内添加属性:
class ProjectDetailController: UIViewController {
var someValue: String?
/* more code */
}
将ProjectDetailController
创建物移至上方,创建后,尝试注入所需的值:
let projectDetailController = self.storyboard?.instantiateViewController(withIdentifier: "projectDetailController") as! UINavigationController
let projectDetailViewController = projectDetailController.viewControllers.first as! ProjectDetailViewController
projectDetailViewController.projectId = id
sideMenuController?.cache(viewControllerGenerator: { projectDetailController }, with: "333")
sideMenuController?.delegate = self as? SideMenuControllerDelegate
sideMenuController?.setContentViewController(with: "333", animated:
Preferences.shared.enableTransitionAnimation)
sideMenuController?.hideMenu()