通过分段控制对开始/结束外观转换的不平衡调用

时间:2016-04-05 17:16:46

标签: ios swift uisegmentedcontrol

所以,我有一个分段控件来切换到视图控制器。 但是,通常,只要我切换,我就会收到此消息:

  

开始/结束外观过渡的不平衡调用

另外,在我得到这个之后,有时会发生视图中的每个对象消失。

以下是代码:

func segmentValueChanged(sender: AnyObject) {


    if sender.selectedIndex == 0 {



        let newController = controllers.newController1
        let oldController = childViewControllers.last as UIViewController!


        self.container.frame.size.height = newController.view.frame.height


        oldController.willMoveToParentViewController(nil)
        addChildViewController(newController)


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


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

                oldController.removeFromParentViewController()
                newController.didMoveToParentViewController(self)


        })

    } else if sender.selectedIndex == 1 {


        let newController = controllers.newController2
        let oldController = childViewControllers.last as UIViewController!

        oldController.willMoveToParentViewController(nil)
        addChildViewController(newController)





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

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

                oldController.removeFromParentViewController()
                newController.didMoveToParentViewController(self)


        })
    }

}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这一行是倒退的:

    self.container.frame.size.height = newController.view.frame.height

您需要设置newController的视图框架!

此外,您未能 newController.view放入界面。这就是为什么你最终没有界面。