Swift 3尝试呈现其视图不在窗口层次结构中 [英] Swift 3 Attempt to present whose view is not in the window hierarchy

查看:70
本文介绍了Swift 3尝试呈现其视图不在窗口层次结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经问了很多遍了,但是即使尝试了大多数可能的事情,我仍然找不到适合我的解决方案. 这是错误消息.

This question has been asked many times but even after trying most of the possible things I am still unable to find a solution that works for me. Here is the error message.

警告:尝试在视图不在窗口层次结构中的< 0x7f8f29e17590>上显示!

Warning: Attempt to present on <0x7f8f29e17590> whose view is not in the window hierarchy!

注意:我没有使用任何导航控制器.

Note: I am not using any navigation controller.

我只是以模态形式显示视图控制器,并且上面有一个按钮用于linkedIn注册.但是,每次我单击linkedin按钮时,都会出现此错误,尽管在其他类中也能正常工作,但我看不到新的linkedIn对话框.

I am just presenting a view controller modally and I have a button on it for linkedIn sign up. But every time I click the linkedin button this error appears and I am unable to see the new linkedIn dialog although it works fine in other classes.

大多数解决方案建议处理viewDidAppear中的按钮单击,该操作已经尝试过,并且不起作用.

Most solutions recommend handling button click in viewDidAppear already tried that and it doesn't work.

我正在使用此代码打开linkedIn注册表单

I am using this code for opening linkedIn signup form

linkedinHelper.authorizeSuccess({ [unowned self] (lsToken) -> Void in

        print("success lsToken: \(lsToken)")
        self.requestProfile()
        }, error: { [unowned self] (error) -> Void in

            print("Encounter error: \(error.localizedDescription)")
        }, cancel: { [unowned self] () -> Void in

            print("User Cancelled!")
    })

推荐答案

我已经解决了这个问题,主要的问题恰恰是它说的视图不在视图层次结构中.为了解决此问题,我们需要使用appDelegate对象将根视图控制器设置为当前视图控制器.这样,该视图现在就进入了视图层次结构,并能够显示更多视图.这是代码

I have resolved the issue the main problem is exactly what it says the view is not in the view hierarchy. In order to resolve this issue we need to set the root view controller to the current view controller using the appDelegate object. So that the view now comes in the view hierarchy and be able to present further views. Here is the code

let initialViewController = UIStoryboard(name: "Main", bundle:nil).instantiateInitialViewController() as UIViewController
let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
appDelegate.window?.rootViewController = initialViewController

请阅读此内容以获取更多信息. https://stackoverflow.com/a/27608804/5123516

Please read this for further information. https://stackoverflow.com/a/27608804/5123516

这篇关于Swift 3尝试呈现其视图不在窗口层次结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆