2012-06-11 36 views
0

我将四到五个视图添加到UIScrollview。UIButton选择器错误

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

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

{ 

    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; 

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

} 

意见添加成功,但是当我点击按钮“无法识别的选择发送到实例0x657e850”所示。我究竟做错了什么?

回答

4

您需要在控制器中实施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:的类。

0

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

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

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

0

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

那是我的方法,其第一个字母以大写字母开头,但我打电话方法与第一个字母小写。