0

I have a View controller with an embedded Container View plus a controller

The Container View hosts a UIPageViewController The View controller has a button, if its clicked I want to update a label in the current displayed page managed by the UIPageView Controller

I am getting the ContainerView Controller with this approach

   @IBAction func sendButtonTouched(sender: AnyObject) {
        if let vc = self.childViewControllers.last as? ContainerViewController{
            vc.pageViewController.view.backgroundColor = UIColor.blueColor()

I get the UIPageViewController and set the color but it does not update

also if go deeper into the rabbit hole to get my currently viewed page I am able to get and set all values but my view never updates

what I really want to do is something like this

 @IBAction func sendButtonTouched(sender: AnyObject) {
    if let vc = self.childViewControllers.last as? ContainerViewController{
        vc.pageViewController.view.backgroundColor = UIColor.blueColor()
        print("make it blue baby")
        if let pageItemController = vc.getCurrentViewController(){
            print(pageItemController.indexLabel.text)
            pageItemController.message = self.messageTextView.text
            pageItemController.messageImage.image = UIImage()
            pageItemController.reloadInputViews()
        }
    }
}

and in ContainerViewController

 func getCurrentViewController()-> MIPViewController?
{
    print("\(self.pageViewController.viewControllers!.count) view controllers")
    if let vc = self.pageViewController.viewControllers!.first as? PageItemViewController
    {
        if vc.index < mipCount
            // must be a MIPViewController
        {
            return vc as? MIPViewController
        }
    }
    return nil
}

in my console output i see

make it blue baby
1 view controllers
Optional("This is a message of the number 0")
Optional("")

so everything is called but as stated no view ever updates

I am probably missing something really basic here, so thank you for your help I also checked other questions e.g. Access Container View Controller from Parent iOS but afaik using the childViewControllers is also valid

Community
  • 1
  • 1
Stefan
  • 508
  • 5
  • 9
  • 1
    Can you not just keep a reference to the ContainerViewController in the ViewController and call a public method that updates what it needs to? – Christopher Kevin Howell Dec 10 '15 at 21:22
  • That works! Now I have to find out why my approach did not work Is if let vc = self.childViewControllers.last as? ContainerViewController no valid way to get the Container View Controller? – Stefan Dec 11 '15 at 08:31
  • It has potential to never be executed if self.childViewControllers.last isn't a ContainerViewController. In which case, your update code would never run. Have you tried seeing what the self.childViewControllers array contains? – Christopher Kevin Howell Dec 11 '15 at 09:21
  • ok thx, I think i definitely tried that however now I can´t reproduce the problem anymore – Stefan Dec 14 '15 at 10:37

0 Answers0