Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I set UIBarButtonItem as anchor of a popover in IOS?

I show a popover controller in my IPad app:

[self.programMapPopOver presentPopoverFromRect:anchor.frame
                        inView:anchor.superview
                        permittedArrowDirections:UIPopoverArrowDirectionAny 
                        animated:YES];

My problem is with anchor: I'd like to set an UIBarButtonItem* as its anchor, but it is not an UIView*, but inView is a view* parameter.

How can I solve this?

Thanks to all!

like image 984
Tom Avatar asked Jun 04 '13 14:06

Tom


2 Answers

In iOS 8 & 9, the presentPopoverFromBarButtonItem:permittedArrowDirections:animated: method is deprecated. You'll want to set the barButtonItem property on the view controller's popoverPresentationController property.

let popover = UIViewController()
popover.modalPresentationStyle = .Popover
if let presentation = popover.popoverPresentationController {
    presentation.barButtonItem = navigationItem.rightBarButtonItem
}
presentViewController(popover, animated: true, completion: nil)
like image 89
Levi McCallum Avatar answered Nov 14 '22 18:11

Levi McCallum


You need to use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:.

like image 25
Scott Berrevoets Avatar answered Nov 14 '22 17:11

Scott Berrevoets