stanley
stanley

Reputation: 529

Create a popup view in Xcode 4

I have a tap recognition in one of my views, on tap of which I should display a popup view from existing nib files. I have added the following code

FeedTabReplyView *d = [[FeedTabReplyView alloc]initWithNibName:@"FeedTabReplyView" bundle:nil];
//d.delegate = self;
//create popover and put V2 in the popover view
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:d]; 
//popoverController.delegate = self;  //optional
CGSize size = CGSizeMake(325, 75);
popoverController.popoverContentSize = size;
[popoverController presentPopoverFromRect:recognizer.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

but it throws an exception:

'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

Upvotes: 0

Views: 1870

Answers (2)

Lorenzo B
Lorenzo B

Reputation: 33428

Omar is right.

From Apple doc:

Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.

Instead of using a third part API, why don't you use UIActionSheet?

If you need to develop an universal app, based on the interface idiom, you could just create a popover (iPad) or an action sheet (iPhone).

Upvotes: 1

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

UIPopoverController works only for the iPad, however for the iPhone there is a very good class WEPopover

its very easy to use, and it has almost all the UIPopoverController methods and properties

Upvotes: 2

Related Questions