is there a way NOT to have the popover dismissed when pressing outside it?

后端 未结 3 1465
执笔经年
执笔经年 2020-12-29 14:14

I know the SDK documentation says

Taps outside of the popover’s contents automatically dismiss the popover.

But I\'m sure the s

3条回答
  •  遥遥无期
    2020-12-29 14:54

    The accepted answer does not really answer the question, "is there a way NOT to have the popover dismissed when pressing outside it?", imo. It does give a possible view but could require hackish access to all parent views and determining what views are on the screen etc. The question could be rephrased as, "how do I make a popover view modal?"

    You would do this like so, with a done button to close the popover:

    UIViewController* vc = [[[UIViewController alloc] init] autorelease];
    
    UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"] style:UIBarButtonItemStyleDone target:self action:@selector(processDoneAction)] autorelease];
    
    [vc.navigationItem setLeftBarButtonItem:doneButton];
    
    vc.modalInPopover = YES;
    //If you want full screen:
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    vc.wantsFullScreenLayout = YES;
    
    UINavigationController* navC = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
    
    UIView* view = create your view
    
    vc.view = view;
    
    UIPopoverController* pc = [[[UIPopoverController alloc] initWithContentViewController:navC] autorelease];
    pc.delegate = self;
    self.popoverController = pc;
    

    Then you'll in your processDoneAction method you will need to dismiss the popover. Other considerations would be dismissing and redisplaying on device orientation changes, but I will leave that to another exercise as that has been answered previously on stackoverflow.

提交回复
热议问题