I figured out a way to get popover to work on iPhone and iPad programmatically !
Create a category to make popover available on iPhone (more details here)
//UIPopover+Iphone.h
@interface UIPopoverController (overrides)
+ (BOOL)_popoversDisabled;
@end
//UIPopover+Iphone.m
@implementation UIPopoverController (overrides)
+ (BOOL)_popoversDisabled { return NO;
}
@end
Create the button which will show the popover and implement the method it calls
ExampleUIViewController.h
@interface ExampleViewController : UIViewController <UIPopoverControllerDelegate>
@property (strong, nonatomic) UIButton *detailButton;
@property (nonatomic, retain) IBOutlet UIPopoverController *poc;
UIPopoverController poc has to be held in an instance variable, more details here.
ExampleUIViewController.m
- (void)viewDidLoad {
_detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_detailButton addTarget:self
action:@selector(showPop:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_detailButton];
}
-(void)showPop:(UIButton *)button {
UIViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
self.poc = [[UIPopoverController alloc] initWithContentViewController:detailsViewController];
[self.poc setDelegate:self];
[self.poc presentPopoverFromRect:_detailButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
- Create the UIViewController that will contain what's displayed inside the popover (called DetailsViewController in the example)
Simply create it in your project by a right click -> New File -> Objective c class -> UIViewController and tick the box "With XIB".
Then a popover will appear right next to the button when tapped.
Tested OK on iOs5 and above.