opening and closing other UIViewControllers - any other approaches than to use protocol & delegate?

前端 未结 2 1772
清歌不尽
清歌不尽 2021-01-15 19:17

The normal way to open another screen from within a FirstVC screen, so one can close it again is like this:

    SecondVC *secondVC = [[SecondVC alloc] initWi         


        
2条回答
  •  没有蜡笔的小新
    2021-01-15 19:47

    You can just call

    dismissViewControllerAnimated:completion:
    

    on the presented viewcontroller, although it is not exactly best practice.

    From Apple's documentation:

    The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

    Also from Apple's documentation though (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html)

    When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it. Although there are several techniques for notifying the presenting view controller that its presented view controller should be dismissed, the preferred technique is delegation.

提交回复
热议问题