UIPopoverController not dismissed when opened from self.navigationItem (inside UINavigationController)

前端 未结 4 1664
醉话见心
醉话见心 2021-01-24 21:06

I have a problem dismissing a popover that was launched from the navigationItem of a UINavigationController. It seems that the navigation item which is inserted by the UINavigat

4条回答
  •  感情败类
    2021-01-24 22:06

    Here's the complete description for popovers in storyboards. Assuming your controller to appear in the popover is named MyPopupController, do this:

    1. Define a segue from the main scene to the MyPopupController scene, using style Popover.
    2. Add a property to MyPopupController.h

      @property (weak, nonatomic) UIPopoverController *popover;
      
    3. Synthesize the property in MyPopupController.m

      @synthesize popover = _popover
      
    4. In the prepareForSegue:sender: method of the main scene controller, set up the popoverproperty:

      UIStoryboardPopoverSegue *ps = (UIStoryboardPopoverSegue *)segue;
      MyPopupController *dc = ps.destinationViewController;
      dc.popover = ps.popoverController;
      
    5. In the viewWillAppear: method of MyPopupController, add the following code (don't forget [super viewWillAppear] as well):

      self.popover.passThroughViews = nil;
      

    You should be done now.

    Thanks to Robert for the basic idea - I just had to find the correct place because presentPopoverFromBarButtonItem is not used when using storyboards. Note that putting (5) into viewDidLoad does not work.

    Have fun coding!

提交回复
热议问题