无法识别的选择器发送到实例UIActionSheet

时间:2012-11-16 09:26:56

标签: uiactionsheet

尝试显示ActionSheet时收到以下错误...

2012-11-16 04:07:03.878 MKS WebTech [814:c07] - [mksWorkOrderViewController _presentActionSheet:asPopoverFromBarButtonItem:orFromRect:inView:withPreferredArrowDirections:passthroughViews:backgroundStyle:animated:]:无法识别的选择器发送到实例0x75a5950

- (IBAction)ActionClick:(id)sender {

    popupSheet = [[UIActionSheet alloc] init];

    [popupSheet setDelegate:self];
    [popupSheet addButtonWithTitle:@"Contact List"];
    [popupSheet addButtonWithTitle:@"Zone Descriptions"];
    [popupSheet addButtonWithTitle:@"Zone Testing"];
    [popupSheet addButtonWithTitle:@"Panels"];
    [popupSheet addButtonWithTitle:@"Time Sheet"];
    [popupSheet addButtonWithTitle:@"Inventory"];
    [popupSheet addButtonWithTitle:@"Other Appt."];
    [popupSheet addButtonWithTitle:@"Alarm History"];
    [popupSheet addButtonWithTitle:@"Service History"];
    [popupSheet addButtonWithTitle:@"Complete"];
    [popupSheet addButtonWithTitle:@"Cancel"];
    [popupSheet setCancelButtonIndex:10];
    // Prepare your action sheet
    [popupSheet showFromBarButtonItem:bntAction animated:NO];

    [popupSheet release];
}

错误发生“showFromBarButtonItem:bntAction”我也尝试过发件人但结果相同

canPerformAction也没有问题......

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    return YES;
}

2 个答案:

答案 0 :(得分:1)

我曾经遇到过这个问题,情况并非如此,但对我来说,这很有效:

  1. 转到Interface Builder
  2. 检查所有对象,问题在于我将一个对象连接到我后来删除的变量,因此它不存在。
  3. 结论:我已将一个对象连接到一个不存在的变量。

    否则,代码看起来很好:)

答案 1 :(得分:0)

对于将来遇到这种情况的其他人(正如我刚才所做的那样):问题在于UIActionSheet在每个响应者链上调用-canPerformAction:@selector(_presentActionSheet:asPopover ...等等)。

因此,由于控制器错误地响应YES,UIActionSheet继续并尝试调用该方法,实现不存在,并且您遇到错误。

正确的解决方法是重新实现你的-canPerformAction:withSender:只返回实际处理的东西。