Ios – Dismiss the popover view

iosipadiphoneuipopovercontrollerxcode

I have a root view controller in which I load a sub view that contains three buttons. When I touch one of them a popover is shown. The popover contains an image view and a bar with a Done button. I want to dismiss this popover when the Done button is touched. To accomplish this I am using this code

- (IBAction)btnDone:(UIBarButtonItem *)sender {
    [self.view removeFromSuperview];

        [APPDELEGATE.parkDetail. popoverController dismissPopoverAnimated:YES];
   // [APPDELEGATE.parkDetail.popoverController dismissPopoverAnimated:YES ];


}

and the popover is presented like this

- (IBAction)btnParkMap:(id)sender {
       [popoverController dismissPopoverAnimated:YES];
    if ([popoverController isPopoverVisible]) {
        [popoverController dismissPopoverAnimated:YES];
    } else {
        parkMap * v = [[parkMap alloc]initWithNibName:@"parkMap" bundle:nil];
        v.contentSizeForViewInPopover = CGSizeMake(350, 300);
        popoverController = [[UIPopoverController alloc] initWithContentViewController:v];
               CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x+330,
                                    self.btnShowPopover.frame.origin.y+170,
                                    self.btnShowPopover.frame.size.width,
                                    self.btnShowPopover.frame.size.height);


        [popoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
          }
}

Best Answer

Try this code

[self dismissViewControllerAnimated:YES completion:nil];

Or try @nirav's ans