Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to dismiss a modal when using storyboards?

Using storyboards, what is the proper way to dismiss a modal?

  • using IBAction and writing code to dismiss after a button click?
  • using segue and notify the parent view controller after a button click?
like image 998
aryaxt Avatar asked Feb 21 '12 17:02

aryaxt


People also ask

How do you dismiss a storyboard?

Select the button that should make the UIViewController Disappear and drag it to the UIViewController you want to go to. In my case it shows **dismiss Controller* because of the name of my Class. Select it and you are done!

How do you dismiss a modal view controller?

According to the View Controller Programming guide for iPhone OS, this is incorrect when it comes to dismissing modal view controllers you should use delegation. So before presenting your modal view make yourself the delegate and then call the delegate from the modal view controller to dismiss.

How do you make an unwind segue in a storyboard?

In your storyboard, create an unwind segue by right-clicking a triggering object and dragging to the Exit control at the top of your view controller's scene.


2 Answers

See Here Dismissing a Presented View Controller about halfway down

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it.

So you should use an IBAction and writing code to dismiss after a button click

like image 141
Bill Bonar Avatar answered Oct 20 '22 15:10

Bill Bonar


According Alex Cio answer for Swift 3 and XCode 8.3:

Create class:

import UIKit  class DismissSegue: UIStoryboardSegue {     override func perform() {         self.source.presentingViewController?.dismiss(animated: true, completion: nil)    } } 

But in storyboard you should choose:

Action Segue -> Custom -> dismiss

Only after this option appear on Action Segue menu

like image 23
UnRewa Avatar answered Oct 20 '22 15:10

UnRewa