iPhone: Error when using the FPPopover class when using it with a UIBarButtonItem

Viewed 2146

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 using a UIBarButtonItem created programmatically. But, I get the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem superview]: unrecognized selector sent to instance 0x6a3e420'

I copy pasted the same code as in the readme file but I just changed the (UIButton*)okButton with (id)sender (id here is UIBarButtonItem*)

-(void)popover:(id)sender
{
    //the view controller you want to present as popover
    TestClass *controller = [[TestClass alloc] init];
    //our popover
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
    //the popover will be presented from the okButton view
    [popover presentPopoverFromView:sender];
    //release
    [controller release];
}

I was thinking maybe it has to do with the UIBarButtonItem which is not a UIButton? Or is it anything else? I tried converting the UIBarButtonItem into UIButton but still gave me the same error. Any solutions to it?

One more note just in case: This is how I programmatically created the navigation bar along with the bar button:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(320, 0, 320, 44)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"By Clubs"];
[navBar pushNavigationItem:navItem animated:NO];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Filter"
                                               style:UIBarButtonItemStyleBordered
                                              target:self
                                              action:@selector(popover:)];


navItem.rightBarButtonItem = editButton;
4 Answers
Related