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

前端 未结 6 1036
终归单人心
终归单人心 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:53

    I've found that usually when I'm attempting to do this in storyboard I'd rather not create extra classes. It still makes sense to perform the dismiss from the presenting view controller, so that requires a class to back it.

    If you create an IBAction in the presenting view controller and name it appropriately e.g.

    - (IBAction)dismissAnyModel:(id)sender
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    Then from storyboard wherever you want to trigger the dismiss from you create an action to the first responder as shown below. You can extend this to work with multiple presenting view controllers by creating unique names for the IBActions.

    Create an outlet to first responder

    Select correct IBAction

    More information on first responder and the responder chain

提交回复
热议问题