Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dismiss current UIViewcontroller and present a new UiViewController

I intend to dismiss my current UIViewController and present to a new UIViewController.

I used the following code

 let newViewController: ViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
 self.presentViewController(newViewController, animated: false, completion: {
         self.dismissViewControllerAnimated(false, completion: nil)
    })

It gave the following error

2016-06-04 11:40:59.864 myApp[851:117649] Trying to dismiss the
presentation controller while transitioning already. (<_UIFullscreenPresentationController: 0x1703e6900>) 2016-06-04 11:40:59.878 ePassBook[851:117649] transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIFullscreenPresentationController: 0x1703e6900>)

like image 277
Cloy Avatar asked Oct 30 '22 02:10

Cloy


1 Answers

Use this Code,

Objective C Code:

[self.navigationController presentViewController:newViewController animated:NO completion:^{
    dispatch_after(0, dispatch_get_main_queue(), ^{
        [self.navigationController dismissViewControllerAnimated:NO completion:nil];
    });
}];

Swift Code:

self.navigationController?.presentViewController(newViewController, animated: false, completion: { () -> Void in
            dispatch_after(0, dispatch_get_main_queue(), { () -> Void in
                self.navigationController?.dismissViewControllerAnimated(false, completion: nil)

            })
        })

hope its helpful

like image 79
Iyyappan Ravi Avatar answered Nov 13 '22 16:11

Iyyappan Ravi