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

前端 未结 6 1051
终归单人心
终归单人心 2021-02-05 00:24

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
6条回答
  •  心在旅途
    2021-02-05 00:38

    To do this inside the UIStoryboard you need first to create an Object of the type UIStoryboardSegue in your project

    Then insert following method inside the class. Here is my class

    @implementation DismissController

    - (void)perform{
    
        UIViewController *sourceVC = self.sourceViewController;
        [sourceVC.presentingViewController dismissViewControllerAnimated:YES 
                                                              completion:nil]; 
    }
    

    Now you can use it inside your UIStoryboard. 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! There is also a very good explanation on this website.

提交回复
热议问题