Ios 在UIContentView中显示视图控制器

Ios 在UIContentView中显示视图控制器,ios,objective-c,presentviewcontroller,Ios,Objective C,Presentviewcontroller,我在rootviewcontrollerabc上安装了pageViewControllerABC,pageViewController包含ViewControllerPQR,其中包含ContentView。我想展示ViewController,但它说 警告:试图在视图不在窗口层次结构中的ABC:0x17e67dc0上显示XYZ:0x17ee0730 我想在哪个控制器上显示视图控制器很高兴您的问题解决了。如果您想从视图控制器以外的任何UIView显示警报,这将有所帮助 此方法获取俯视图控制器,以便

我在rootviewcontrollerabc上安装了pageViewControllerABC,pageViewController包含ViewControllerPQR,其中包含ContentView。我想展示ViewController,但它说

警告:试图在视图不在窗口层次结构中的ABC:0x17e67dc0上显示XYZ:0x17ee0730


我想在哪个控制器上显示视图控制器很高兴您的问题解决了。如果您想从视图控制器以外的任何UIView显示警报,这将有所帮助

此方法获取俯视图控制器,以便您可以从中显示警报:

func currentTopViewController() -> UIViewController{

    var topVC: UIViewController? = UIApplication.shared.delegate?.window??.rootViewController

    while ((topVC?.presentedViewController) != nil) {

        topVC = topVC?.presentedViewController

    }

    return topVC!

}

func showAlert() { // This presents your alert from the received view controller object

    let alertController: UIAlertController = UIAlertController.init(title: "title", message: "message", preferredStyle: .alert)

    let alertAction = UIAlertAction.init(title: "OK", style: .default) { (UIAlertAction) in
            //Your action    
    }

    alertController.addAction(alertAction)

    currentTopViewController().present(alertController, animated: true, completion: nil)

}

添加工作完成代码。耶!显示你的代码!你说的包含是什么意思?是否已将viewcontroller的视图添加为子视图?已解决。实际上,我正在将pageViewController设置为navigationController