简体   繁体   中英

how to show the UIPopoverController when button clicked in iPhone

I have a problem with UIPopoverController. On button press I need to display the UIPopoverController. This is the code.

-(IBAction)hintButton:(id)sender{ 
CGRect contentRect = CGRectMake(0, 0, 200, 40);
UIViewController* popoverContent = [[UIViewController alloc] init];
popoverContent.view = hintB;

popoverContent.contentSizeForViewInPopover = contentRect.size;
if(popoverController == nil){   //make sure popover isn't displayed more than once in the view
    popoverController = [[UIPopoverController alloc]initWithContentViewController:popoverContent]; 

    [popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popoverController.delegate = self;
 }  

}

When I press the button application crashes.

UIPopoverController cannot be used for iPhone applications. It's only for iPad apps.

However, you can have this functionality by creating custom UIPopoverController. You can find a custom UIPopoverController sample here .

Let me know if you have any similar questions.

Thanks,

MinuMaster

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM