问题描述
我有一个导航控制器和根视图.然后在该根视图中,我将视图推到那里,必须单击以观看内容,如果已登录,如果未登录,则将使用以下代码打开模式视图控制器.
I have a navigation controller and root view. Then in that root view, I pushed a view there I have to click to watch the content, if logged in, if not logged it, it would open a modal view controller with the below code.
var vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
self.tabBarController!.presentViewController(vc, animated: true, completion: nil)
在viewdidload()中,我有一个nsnotification,以便当用户从登录模式登录回时可以得到通知
In viewdidload() i have a nsnotification so that I could get notified when user loggedinback from login modal
NSNotificationCenter.defaultCenter().addObserver(self, selector: ("didDismissSecondViewController:"), name: "SecondViewControllerDismissed", object: nil)
完成所有工作后,在Login控制器中,我编写了以下代码
In Login controller after all work I wrote the below code
self.dismissViewControllerAnimated(true, completion: {NSNotificationCenter.defaultCenter().postNotificationName("SecondViewControllerDismissed", object: nil, userInfo: nil)});
所以在我的第一个视图控制器中,我编写了以下代码
So in my first view controller I wrote the below code
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()
}
})
}
但是,当它在关闭登录控制器后尝试显示视图控制器时,显示不鼓励在分离的视图控制器上提供视图控制器"错误并崩溃了.
However, when it tries to present the view controller after dismiss login controller, it shows "Presenting view controllers on detached view controllers is discouraged" Error and it crashed.
推荐答案
感谢上帝,我找到了答案!
Thank God I found the answer!!!
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)});
这篇关于“不建议在分离的视图控制器上呈现视图控制器".呈现模态时的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!