所以,我有一个分段控件来切换到视图控制器。 但是,通常,只要我切换,我就会收到此消息:
开始/结束外观过渡的不平衡调用
另外,在我得到这个之后,有时会发生视图中的每个对象消失。
以下是代码:
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)
})
}
}
我该如何解决这个问题?
答案 0 :(得分:0)
这一行是倒退的:
self.container.frame.size.height = newController.view.frame.height
您需要设置newController
的视图框架!
此外,您未能将 newController.view
放入界面。这就是为什么你最终没有界面。