0

我正在以编程方式创建一个带有图像的 UIButton。

UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];
[bericht setBackgroundImage:[UIImage imageNamed:@"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];

- (void) imageClicked:(UIButton *) sender {
   NSLog(@"test message");
}

当我单击此按钮时,我收到以下错误代码:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[__NSSetM goToFirstTrailer:]: unrecognized selector sent to instance 0x7fdaf1e73fe0'

有谁知道解决方案?

4

1 回答 1

1

将您的选择器方法更改为 imageClicked。

UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)];

[bericht setBackgroundImage:[UIImage imageNamed:@"bericht.png"] forState:UIControlStateNormal];
[bericht addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:bericht];

- (void) imageClicked:(UIButton *) sender {
   NSLog(@"iaksdkjas");
}
于 2014-12-12T11:28:25.197 回答