I am building an app to present UIViewController
and dismiss the current UIViewController
at the same time.
Currently I'm in viewcontroller1
and i want to present viewcontroller2
as main controller and dismiss viewcontroller1
to remove it from memory, so viewcontroller2
will be the main controller after presenting and there is no viewcontroller1
in stack.
I've tried :
let controller = storyboard?.instantiateViewControllerWithIdentifier("controller2") as! viewcontroller2
controller.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
self.dismissViewControllerAnimated(false) { () -> Void in
self.presentViewController(controller, animated: false, completion: nil)
}
But it gave me : 0x7fee28711900> whose view is not in the window hierarchy!
Is there is a way to do that ?
If you want to replace a UIViewController
entirely, you should do this:
UIApplication.sharedApplication().keyWindow?.rootViewController = newController
This however will not cross-dissolve.
If you need to cross, you'll just have to present the new view controller "over" the old one, or follow the advice in this post and re-write it Swift:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.