I am using the FPPopover class which creates popups for iPhones. I followed the exact steps that are in the readme file but instead of using a UIbutton from a xib file, I am
I was getting the same error. Solution is to create a UIButton Programatically (at the same place of UIBar button item - set the appropriate coordinates) and then present popover from UIButton. Then hide the UIButton.
This code worked for me:
-(void)testMethod {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// set action as NULL if you dont need any method/functionality to call
[button addTarget:self action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(130, -40, 160.0, 40.0);
[self.view addSubview:button];
AlertsViewController *controller = [[AlertsViewController alloc] init];
//our popover
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
//the popover will be presented from the Button view
[popover presentPopoverFromView:button];
//hide the button
button.hidden = YES;
}
-(void)aMethod {
// Write any functionality if you need
}
Hope this helps. Let me know if you get any issue.
the presentPopoverFromView is only accepting a UIView subclass. UIBarButtonItem is not a subclass of UIView, so you need to find the view related to that button item. This is the solution I'm using with FPPopoverController
UIBarButtonItem *buttonItem = sender;
UIView* btnView = [buttonItem valueForKey:@"view"];
//On these cases is better to specify the arrow direction
[popover setArrowDirection:FPPopoverArrowDirectionUp];
[popover presentPopoverFromView:btnView];
This should work! Let me know!
Mostly applications display popover from BarButtonItem. FPPopOverController doesn't support this. So, in my opinion you should use: WYPopOverController
That's b/c UIBarButtonItem inherits from UIBarItem
and NSObject
. Only UI elements that inherit from UIView
have superview
properties.