Author Topic: How do I dismiss a modal view?  (Read 5708 times)


  • Administrator
  • *****
  • Posts: 719
    • View Profile
How do I dismiss a modal view?
« on: October 14, 2013, 10:36:36 PM »
Typically, the user taps a Done button to dismiss a modal view. You can create an action method for the Done button that contains the following code that dismisses the view controller, which in turn hides the view.

In Swift:

Code: [Select]
@IBAction func done(sender: AnyObject) {
     self.dismissViewControllerAnimated(true, completion: nil)

In Objective-C:

Code: [Select]
- (IBAction)done:(id)sender {

[self dismissViewControllerAnimated:YES completion:nil];

To see this code in action, check out Book 3: Navigating Xcode 5, in Chapter 7: The User-Interface Controls under the section "Switching Between Standard, Satellite, and Hybrid".

All the best!
Author of Learn to Code in Swift:
« Last Edit: July 16, 2015, 03:38:11 AM by kjmcneish »