【问题标题】:ios unrecognized selectors sent to instanceios无法识别的选择器发送到实例
【发布时间】:2013-05-10 09:22:08
【问题描述】:

已经解决了unrecognized selector sent to instance 的优秀答案,但我仍然无法调试。

我得到的错误是

* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UITabBarController disableTabBarItemWithIndexNo:]:无法识别的选择器发送到实例 0x1184dfa0” * 首先抛出调用栈:

设置断点问题似乎来自这里

[appdelegate tabBarController:shouldSelectViewController:]

[待定禁用TabBarItemWithIndexNo:index];

我相信导致问题的代码是这样的:

- (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;
}

现在这让我发疯了,我确信 IB 中的所有内容都已正确连接,并且自定义控制器应该响应方法调用。 非常感谢任何帮助!

【问题讨论】:

  • 发布你的CustomTabBarController接口,你定义了那里的方法并实现了吗?发布您的 disableTabBarItemWithIndexNo 实现
  • 为什么tabbar代理在app控制器中?
  • 你是在 iPhone 还是 iPad 上运行这段代码?

标签: ios objective-c xcode


【解决方案1】:

您应该检查CustomTabBarController 内部是否定义了disableTabBarItemWithIndexNo 方法。因为这种类型的错误unrecognized selector sent to instance总是会导致,如果对应的类没有那个方法的实现,那么如果你调用那个方法,那么应该在那里定义那个方法。

为了避免此类错误,您应该首先检查特定方法的实现 如下图。

 if([tbc respondsToSelector:@selector(disableTabBarItemWithIndexNo:)])
//this will return YES if that method implemented there in `CustomTabBarController` Class otherwise will return NO.    {
         [tbc disableTabBarItemWithIndexNo :NO];
   }

【讨论】:

    【解决方案2】:

    只需检查您将自定义标签栏的类设置为CustomTabBarControllerin nib 而不是UITabBarController

    您也可以添加if([tbc respondsToSelector:@selector(disableTabBarItemWithIndexNo:)]) 在调用此方法以防止崩溃之前。

    【讨论】:

    • 哇哦!已经检查了 100 次 CustomTabBarController 已被选中 - 但正在查看 mainwindow-ipad.xib 而不是主窗口笔尖!谢谢谢谢!!
    【解决方案3】:

    鉴于错误文本:

    -[UITabBarController disableTabBarItemWithIndexNo:]

    问题似乎是你有一个UITabBarController 的实例,而不是你的CustomTabBarController 子类。

    【讨论】:

      猜你喜欢
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 2019-08-28
      • 2012-07-24
      相关资源
      最近更新 更多