Popover for iPhone with Xcode 5

I wanted to reuse the popover for the iPhone described in this video , which is exactly what I need.

The problem is that I could not bind the UIViewController property to the UIViewController UIViewController , as in the video.

One difference of the video is that it was made using Xcode 4.2, and I am using Xcode 5.

So, the question is: how to make a popover for the iPhone, as in video on Xcode 5?

Here is the Xcode 5 project I'm struggling with.

+7
ios objective-c iphone xcode foundation
source share
1 answer

I figured out a way to make popover work on the iPhone and iPad programmatically!

  • Create a category to make popover available on iPhone (more info here )

     //UIPopover+Iphone.h @interface UIPopoverController (overrides) + (BOOL)_popoversDisabled; @end //UIPopover+Iphone.m @implementation UIPopoverController (overrides) + (BOOL)_popoversDisabled { return NO; } @end 
  • Create a button that displays a popover and implements the method that it calls.

ExampleUIViewController.h

 @interface ExampleViewController : UIViewController <UIPopoverControllerDelegate> @property (strong, nonatomic) UIButton *detailButton; @property (nonatomic, retain) IBOutlet UIPopoverController *poc; 

The UIPopoverController poc should be stored 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 a UIViewController that will contain what is displayed inside the popover (in the example, the DetailsViewController element)

Just create it in your project by right-clicking → New File → Objective c class → UIViewController and check the “With XIB” box.

Then, when you click on the button, it will appear next to the button.

Tested OK on iOs5 and above.

+14
source share

All Articles