UIButton 选择器错误



我正在向UIScrollview添加四到五个视图。

我正在运行时动态创建该视图。

所有视图都包含一个按钮。

{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(category_selected:) forControlEvents:UIControlEventTouchUpInside];
}

视图已成功添加,但是当我单击按钮时,将显示"无法识别的选择器发送到实例0x657e850"。我做错了什么?

您需要在控制器中实现 category_selected: 方法。签名应如下所示:

- (void)category_selected:(UIButton*)sender
{
    // The sender is the button that was pressed.
}

当您像这样设置按钮时:

[button addTarget:self action:@selector(category_selected:) forControlEvents:UIControlEventTouchUpInside];

我假设您是从控制器调用的,因此控制器self,这是必须实现category_selected:的类。

您是否在类中定义了方法category_selected:。

[按钮添加目标:自操作:@selector(category_selected:)forControlEvents:UIControlEventTouchUpInside];

category_selected:方法应在设置上述操作的类中定义。

我有Category_Selected方法。 我打电话给category_selected。

也就是说,我有第一个字母以大写字母开头的方法,但我调用的第一个字母小写的方法。

最新更新