Search code examples
iphoneobjective-ciosibaction

Application crashes when a method is called programmatically but works in IB


When I run this action from a button in IB the method is called fine. If I run it from code the app crashes with an unrecognized selector sent to instance error

here's the method:

-(void)bottomCenter:(id)sender
{
    [self popover:sender];
}

-(void)popover:(id)sender
{
    //the controller we want to present as a popover
    DemoTableController *controller = [[DemoTableController alloc] initWithStyle:UITableViewStylePlain];
    controller.delegate = self;
    popover = [[FPPopoverController alloc] initWithViewController:controller];

    //popover.arrowDirection = FPPopoverArrowDirectionAny;
    popover.tint = FPPopoverDefaultTint;

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        popover.contentSize = CGSizeMake(300, 500);
    }
    else {
        popover.contentSize = CGSizeMake(200, 300);
    }

    popover.arrowDirection = FPPopoverArrowDirectionAny;

    //sender is the UIButton view
    [popover presentPopoverFromView:sender];
}

and this is how I call it from a toolBar button:

 UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icons-footer-filter.png"] style:UIBarButtonItemStylePlain target:self action:@selector(bottomCenter:)];

am I calling it incorrectly with target:self action:@selector(bottomCenter:) ?


Solution

  • This solved my problem: stackoverflow link

    The issue was due to UIBarButtonItem not a subclass of UIView...