Creating a UIPopoverController

I am creating a popover in Xcode 4.3. I don't get any error messages, but when I click build and run and I click the button that should open the popover screen, the application crashes and highlights the line in my code in green and says:

Topic 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.

+4
source share
5 answers

A few suggestions here ...

First, do you use automatic link counting (ARC)? if so, you need to have an instance variable to control your UIPopoverController . For instance:

 @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 should do this, because if not, ARC will release a popover just created for you at the end of your IBAction. In addition, you do this to have a link for your popover. See note. This is also true if you are not using ARC.

NOTE. At some point, you may need to release a popover. For example, in - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController do

 self.popover = nil; 

Then, if your SecondView is a UIViewController call to SecondViewController . But this is a simple sentence for naming.

Finally, the correct way to display a popover from the action sender (for example, a UIButton ) instead of hard code 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]; } 
+16
source
 -(IBAction)showpop:(id)sender { UIPopoverController *pop = [[UIPopoverController alloc]initWithContentViewController:popoverview]; [pop setDelegate:self]; [pop presentPopoverFromRect:popbutton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } 
+4
source

The second view you pass to the UIPopOverController is the UIView . Do this with the UIViewController because the UIPopOverController expects a UIViewController .

-Suraj

+3
source

Make sure you simulate an iPad

 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 } 
+2
source

Set the link below for the popover tutorial in ios

UIPopOverController Tutorial

0
source

Source: https://habr.com/ru/post/1401997/


All Articles