"Presenting view controllers on detached view controllers is discouraged" 呈现模态时的消息
"Presenting view controllers on detached view controllers is discouraged" message when presenting modal
我有一个导航控制器和根视图。然后在该根视图中,我在那里推送了一个视图,我必须单击才能观看内容,如果已登录,如果未登录,它将使用以下代码打开一个模态视图控制器。
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)
完成所有工作后,我在登录控制器中编写了以下代码
self.dismissViewControllerAnimated(true, completion: {NSNotificationCenter.defaultCenter().postNotificationName("SecondViewControllerDismissed", object: nil, userInfo: nil)});
所以在我的第一个视图控制器中我写了下面的代码
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()
}
})
}
然而,当它试图在关闭登录控制器后显示视图控制器时,它显示 "Presenting view controllers on detached view controllers is discouraged" 错误并且崩溃了。
感谢上帝,我找到了答案!!!
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)});
我有一个导航控制器和根视图。然后在该根视图中,我在那里推送了一个视图,我必须单击才能观看内容,如果已登录,如果未登录,它将使用以下代码打开一个模态视图控制器。
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)
完成所有工作后,我在登录控制器中编写了以下代码
self.dismissViewControllerAnimated(true, completion: {NSNotificationCenter.defaultCenter().postNotificationName("SecondViewControllerDismissed", object: nil, userInfo: nil)});
所以在我的第一个视图控制器中我写了下面的代码
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()
}
})
}
然而,当它试图在关闭登录控制器后显示视图控制器时,它显示 "Presenting view controllers on detached view controllers is discouraged" 错误并且崩溃了。
感谢上帝,我找到了答案!!!
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)});