实例化视图时传递值

时间:2018-12-11 17:07:56

标签: swift

需要通过以下方式将值从一个视图控制器添加到另一视图控制器。我能够成功移动到另一个页面,但无法传递值

   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()

1 个答案:

答案 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()