user1253207
user1253207

Reputation: 45

Creating a UIPopoverController

I'm creating a popover in Xcode 4.3. I don't get any error messages but when I click build and run and I press the button that is supposed to open the popover screen, the app crashes and highlights in green a line in my code and says:

Thread 1: breakpoint 2.1..

What does this mean and how can I fix it?

- (IBAction)popOver
{
    SecondView *secondview = [[SecondView alloc] init];
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:secondview];    

    [popover setDelegate:self];    

    [popover presentPopoverFromRect:CGRectMake(801, 401, 300, 200) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    [popover setPopoverContentSize:CGSizeMake(300, 200)];   
}

Thanks in advance.

Upvotes: 4

Views: 29170

Answers (5)

Aman_ClickApps
Aman_ClickApps

Reputation: 1

Check below link for popover tutorial in ios

UIPopOverController Tutorial

Upvotes: 0

Lorenzo B
Lorenzo B

Reputation: 33428

Few suggestions here...

First, are you using Automatic Reference Counting (ARC)? if yes you need to have an instance variable to control your UIPopoverController. For example:

@property (strong, nonatomic) UIPopoverController* popover;

if you are not using ARC create a retain one:

@property (retain, nonatomic) UIPopoverController* popover;

In the first case you have to do this because if not, ARC will release for you the just created popover at the end of your IBAction. In addition you do this to have a reference for your popover. See NOTE. This is valid also if you don't use ARC.

NOTE At some point you could have the necessity to release the popover. For example in - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController do

self.popover = nil;

Then, if your SecondView is a UIViewController call it SecondViewController. But this is a simple naming suggestion.

Finally, the correct way for display the popover from the action sender (e.g a UIButton), instead of hardcode positions, could be:

- (IBAction)openPopover:(id)sender
{
    // create the popover here...

    UIButton* senderButton = (UIButton*)sender;

    [popover setPopoverContentSize:CGSizeMake(300, 200)];
    [popover presentPopoverFromRect:senderButton.bounds inView:senderButton permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

Upvotes: 16

Suran
Suran

Reputation: 1227

The SecondView that you're passing into UIPopOverController is a UIView. Make it a UIViewController, because, what UIPopOverController expects is a UIViewController.

-Suraj

Upvotes: 3

Nadella Ravindra
Nadella Ravindra

Reputation: 41

-(IBAction)showpop:(id)sender
{
UIPopoverController *pop = [[UIPopoverController alloc]initWithContentViewController:popoverview];
[pop setDelegate:self];
[pop presentPopoverFromRect:popbutton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

}

Upvotes: 4

Omar Freewan
Omar Freewan

Reputation: 2678

Make sure you simulate on iPad device

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
   // We are using an iPhone
    UIActionSheet *alertSheet = [[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Library", nil];
   [alertSheet setTag:0];
   [alertSheet setDelegate:self];
   [alertSheet showFromTabBar:[[self tabBarController] tabBar]];
   [alertSheet release];
}else {
    // We are using an iPad
    /// here you should pass UIViewController inside the popover
    /// follow @flexaddicted notes to implement the popover
}

Upvotes: 2

Related Questions