UIPopoverController for iphone not working?

Ravindhiran picture Ravindhiran · Feb 9, 2013 · Viewed 46.2k times · Source

I need to use a UIPopOverController for my iPhone app ,i searched stackoverflow someone said UIPopoverController does not run on iphone iphone device WHY?.when i run on iphone device i got this error reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

 -(void)btnSetRemainderTapped:(UIButton *)button
{
   setReminderView =[[SetRemainderView alloc]initWithNibName:@"SetRemainderView" bundle:[NSBundle mainBundle]];
setReminderView.contentSizeForViewInPopover = CGSizeMake(setReminderView.view.frame.size.width, setReminderView.view.frame.size.height);
setReminderView.delegate = self;
popOverController = [[UIPopoverController alloc]
                      initWithContentViewController:setReminderView] ;
 CGRect rect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1, 1);
[popOverController presentPopoverFromRect:rect
                                        inView:self.view
                      permittedArrowDirections:UIPopoverArrowDirectionAny
                                      animated:YES];
}

can any one help me?

Answer

Philip J. Fry picture Philip J. Fry · Feb 15, 2013

You CAN use popoverController in iPhone apps.

1. Create a category

// UIPopoverController+iPhone.h file
@interface UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled;
@end

// UIPopoverController+iPhone.m file
@implementation UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled {
    return NO; 
} 
@end

2. Import it to your class and use popover in iPhone as usual.

But remember that this is private method and Apple can reject your app. But I know people who use this normally and Apple published their apps.