繁体   English   中英

iOS单击动态UIButton崩溃

[英]iOS click on dynamic UIButton crashes

我正在以编程方式创建带有图像的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'

有人知道解决方案吗?

将选择器方法更改为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");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM