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

kjmcneish

  • 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!
Kevin
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
« Last Edit: July 16, 2015, 03:38:11 AM by kjmcneish »