在transitionFromViewController中传递数据

时间:2015-09-05 09:07:48

标签: ios swift uiviewcontroller

我正在使用transitionFromViewController使用分段控件在两个视图控制器之间切换。

这是我的代码:

    @IBAction func valueChanged(sender: AnyObject) {

    var newController = storyboard?.instantiateViewControllerWithIdentifier(viewControllerIdentifiers[sender.selectedSegmentIndex]) as! UIViewController
    let oldController = childViewControllers.last as! UIViewController



    oldController.willMoveToParentViewController(nil)
    addChildViewController(newController)
    newController.view.frame = oldController.view.frame

    if viewControllerIdentifiers[sender.selectedSegmentIndex] == "first" {

        let vc = newController as! userProfileViewController
        vc.userToShow = self.userToShow

    }

    transitionFromViewController(oldController, toViewController: newController, duration: 0.25, options: .TransitionCrossDissolve, animations:{ () -> Void in
        // nothing needed here




        }, completion: { (finished) -> Void in
            oldController.removeFromParentViewController()

            newController.didMoveToParentViewController(self)

    })

}

是否可以从Parent?

将数据传递给childViewControllers

1 个答案:

答案 0 :(得分:0)

transitionFromViewController(oldController, toViewController: newController, duration: 0.25, options: .TransitionCrossDissolve, animations:{ () -> Void in
        newController.property = currentProperty
        //basically here is where you can pass the data. I used a property as an example. You know what you need to send :)
    }, completion: { (finished) -> Void in
        oldController.removeFromParentViewController()
        newController.didMoveToParentViewController(self)
})