Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function to finish a UIviewcontroller like in android?

In android you can call the method finish() and the activity closes. Is there something similar in swift?

like image 344
Megaetron Avatar asked Jul 03 '15 13:07

Megaetron


2 Answers

Not quite. In iOS land you have to more explicitly call viewController.dismissViewControllerAnimated(true, completion: nil) if your view controller is a modal or one of the various dismissal methods on UINavigationController if your viewController was pushed on to the screen.

In Swift 3 this function is:

viewController.dismiss(animated: true)
like image 135
villy393 Avatar answered Nov 15 '22 11:11

villy393


Simple Elegant Solution, write the below line to dismiss your current View Controller

self.dismiss(animated: true, completion: nil)
like image 20
Naveed Ahmad Avatar answered Nov 15 '22 12:11

Naveed Ahmad