UIViewController容器未显示ChildViewController

时间:2018-06-23 17:34:25

标签: ios iphone swift

我尝试实现左侧面板,但是无论何时实现,似乎除了容器之外什么都不会显示。

以下是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    initCenter(screen: showVC)
}

func initCenter(screen: ShowWhichVC) {
    var presetingController: UIViewController
    showVC = screen

    if dashboardVC == nil {
        dashboardVC = UIStoryboard.dashboardController()
        dashboardVC.delegate = self
    }
    presetingController = dashboardVC
    if let con = centerController {
        con.view.removeFromSuperview()
        con.removeFromParentViewController()
    }
    centerController = presetingController
    view.addSubview(centerController.view)
    self.addChildViewController(centerController)
    centerController.didMove(toParentViewController: self)
}



private extension UIStoryboard {

    class func mainStoryboard() -> UIStoryboard {
        return UIStoryboard(name: "Main", bundle: Bundle.main)
    }

    class func leftPanelController() -> LeftPanelController? {
        return mainStoryboard().instantiateViewController(withIdentifier: "LeftPanelController") as? LeftPanelController
    }

    class func dashboardController() -> DashboardController? {
        return mainStoryboard().instantiateViewController(withIdentifier: "DashboardController") as? DashboardController
    }
}

注意:DashboardControllerLeftPanelController UI是用编程方式编写的,这与它有关吗?谢谢!

  

更新GMS

2018-06-24 02:05:46.791965+0800 Pegasus[32657:577667] Google Maps SDK for iOS and Google Places API for iOS version: 2.7.30514.0 2018-06-24 02:05:46.808461+0800 Pegasus[32657:577704] TIC Read Status [2:0x0]: 1:57 2018-06-24 02:05:46.808596+0800 Pegasus[32657:577704] TIC Read Status [2:0x0]: 1:57

我认为现在它与GMSMapview有关

1 个答案:

答案 0 :(得分:0)

我找到了解决方案!对其进行彻底检查后,发现centerController的视图大小已设置为0,所以我要做的是向其添加一个与屏幕大小相关的大小。

centerController.view.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)