0

Have worked through the excellent answers here unrecognized selector sent to instance but am still unable to debug this.

error I get is

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController disableTabBarItemWithIndexNo:]: unrecognized selector sent to instance 0x1184dfa0' * First throw call stack:

Setting breakpoint the issue appears to be from here

[appdelegate tabBarController:shouldSelectViewController:]

[tbc disableTabBarItemWithIndexNo:index];

I believe the code causing the issue is this:

- (BOOL)tabBarController:(CustomTabBarController *)tbc shouldSelectViewController:(UIViewController *)viewController {
if ([viewController isMemberOfClass:[ActionViewController class]])  {
    NSInteger index = [tbc.viewControllers indexOfObject:viewController];
    CGRect frame = [[[self tabBarItemViewList:tbc] objectAtIndex:index] frame];
    ActionViewController* content = [[ActionViewController alloc] init];
    UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:content];
    [content release];
    popover.delegate = self;
    popover.popoverContentSize = CGSizeMake(popover.popoverContentSize.width, 411.0);

    [tbc disableTabBarItemWithIndexNo:index];

    // Store the popover in a custom property for later use.
    self.currentPopover = popover;
    [self.currentPopover presentPopoverFromRect:frame inView:tbc.tabBar permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    return NO;
}

This is now driving me crazy, am sure have everything hooked up in IB correctly, and the custom controller should respond to the method call. Any help very much appreciated!

Community
  • 1
  • 1
Zeb99
  • 103
  • 2
  • 11

3 Answers3

2

You should check out inside the CustomTabBarController whether you have defined disableTabBarItemWithIndexNo method. because this type of Error unrecognized selector sent to instance always caused, if the corresponding Class don't have the implementation of that method.then if you calling that method then that method should be defined there.

And for avoiding such error you should firstly check that implementation of particular method As shown below.

 if([tbc respondsToSelector:@selector(disableTabBarItemWithIndexNo:)])
//this will return YES if that method implemented there in `CustomTabBarController` Class otherwise will return NO.    {
         [tbc disableTabBarItemWithIndexNo :NO];
   }
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
1

Just check you set class of custom tab bar to CustomTabBarControllerin nib instead of UITabBarController.

And also you can add if([tbc respondsToSelector:@selector(disableTabBarItemWithIndexNo:)]) before calling this method to prevent crash.

Divyu
  • 1,325
  • 9
  • 21
  • Oh wow! Had checked 100 times that CustomTabBarController had been selected - but was looking at mainwindow-ipad.xib not the mainwindow nib! Thankyou thankyou!! – Zeb99 May 10 '13 at 10:12
1

Given the error text:

-[UITabBarController disableTabBarItemWithIndexNo:]

The problem seems to be that you've got an instance of UITabBarController, not your CustomTabBarController subclass.