I am making an iPad app where I programmatically place UIButtons on a UIImageView inside a UIScrollView.
When someone pushes one of these buttons I would like to present a UIPopover. Since the buttons have been added programmatically, I also have to present the popover programmatically.
Here is my code for presenting the popover:
- (void)buttonHandler:(UIButton *)sender
{
PushButtonViewController *controller = [[PushButtonViewController alloc] initWithButtonID:@"hej"];
_pushButtonPopover = [[UIPopoverController alloc] initWithContentViewController:controller];
_pushButtonPopover.delegate = self;
if(![_pushButtonPopover isPopoverVisible]) {
[_pushButtonPopover presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[_pushButtonPopover dismissPopoverAnimated:YES];
}
}
This is the initializer of the popover view controller:
- (id)initWithButtonID:(NSString *)buttonID
{
self = [super init];
self.buttonID = buttonID;
return self;
}
The problem is that when I do so, I get an empty popover:
However, when I use a pre-inserted button, hooked up with a segue i the Storyboard, everything works just fine:
I really hope that you might have some suggestions to what I might be doing wrong. Thank you in advance!
I seem to have found the answer myself. For some reason you have to instantiate your ViewController from the storyboard like this:
This way the view is displayed correctly.