gpt4 book ai didi

ios - "Presenting view controllers on detached view controllers is discouraged"呈现模态时的消息

转载 作者:行者123 更新时间:2023-11-30 14:09:52 38 4
gpt4 key购买 nike

我有一个导航 Controller 和 Root View 。然后在该 Root View 中,我将一个 View 推到那里,我必须单击才能观看内容,如果已登录,如果未登录,它将使用以下代码打开一个模态视图 Controller 。

        var vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
self.tabBarController!.presentViewController(vc, animated: true, completion: nil)

在 viewdidload() 中,我有一个 nsnotification,以便当用户从登录模式重新登录时我可以收到通知

 NSNotificationCenter.defaultCenter().addObserver(self, selector: ("didDismissSecondViewController:"), name: "SecondViewControllerDismissed", object: nil)

在完成所有工作后,在登录 Controller 中我编写了以下代码

 self.dismissViewControllerAnimated(true, completion: {NSNotificationCenter.defaultCenter().postNotificationName("SecondViewControllerDismissed", object: nil, userInfo: nil)});

所以在我的第一个 View Controller 中我编写了以下代码

func didDismissSecondViewController(sender: AnyObject)
{
NSLog("Called ns notifications")
dispatch_async(dispatch_get_main_queue(),{

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if Reachability.isConnectedToNetwork() == true {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : VideoPlayViewController = storyboard.instantiateViewControllerWithIdentifier("video") as! VideoPlayViewController
vc.movieUrl = self.movieURL
NSLog("URL:- \(self.movieURL)")
let navigationController = UINavigationController(rootViewController: vc)

self.presentViewController(navigationController, animated: true, completion: nil)

}
else
{

var alert = UIAlertView(title: "No Internet connection", message: "Please ensure you are connected to the Internet. Connect to internet and and choose any sorting option to reload.", delegate: self, cancelButtonTitle: "Cancel")
alert.addButtonWithTitle("Ok")
alert.show()


}


})

}

但是,当它在关闭登录 Controller 后尝试显示 View Controller 时,它会显示“不鼓励在分离的 View Controller 上显示 View Controller ”错误并崩溃。

最佳答案

感谢上帝,我找到了答案!!!

var viewCon:UIViewController = self.presentingViewController!

self.dismissViewControllerAnimated(true, completion: {let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

let vc : VideoPlayViewController = storyboard.instantiateViewControllerWithIdentifier("video") as! VideoPlayViewController

vc.movieUrl = self.movieUrl

let navigationController = UINavigationController(rootViewController: vc)

viewCon.presentViewController(navigationController, animated: true, completion: nil)});

关于ios - "Presenting view controllers on detached view controllers is discouraged"呈现模态时的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31876720/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com