Here's my code
-(IBAction)showMenu:(id)sender
{
Demo *mainMenuTableView = [[Demo alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc]initWithContentViewController:mainMenuTableView];
[pop setDelegate:self];
}
Demo is my xib that contains a tableview controller stuff. This "Demo" works just fine as a fullscreen view.
I'm trying to create a popover with this view, but I've tried what I think is every other solutions on stackoverflow, but I still cannot determine how to create and call the popover...
I'm sure I'm like a line of code or two away... I hope. Any help would be appreciated!
Thx!
After you create the popover controller, you have to tell it to present the popover. You can use either presentPopoverFromRect:inView:permittedArrowDirections:animated: or presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. For example, I assume that you have connected showMenu: as the action of a UIButton. So you can add this at the end of showMenu::
UIButton *button = (UIButton *)sender;
[pop presentPopoverFromRect:button.bounds
inView:button
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
You also need to put a reference to the popover controller in an instance variable or property. Otherwise the popover controller will be deallocated when showMenu: returns, which will cause a crash. Thanks to Floydian for pointing this out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With