我正在尝试处理 UITableView 单元格中 UIButton 的点击事件,但不幸的是应用程序崩溃并显示错误消息:
unrecognized selector sent to instance 0x7f95984cbaf0
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// this is a simplified version of this method for brevity.
NSMutableArray* views = [NSMutableArray array];
UIButton* button = [UIButton buttonWithThinBorderedColor_QAN:[UIColor colorForPrimaryUse]
highlightedColor:nil
disabledColor:nil];
[button addTarget:self action:@selector(showSomething) forControlEvents:UIControlEventTouchUpInside];
button.tag = indexPath.row;
[views addObject:button];
[cell setContents:views withConfiguration:configuration];
return cell;
}
在 myViewController.h(简化版)中我有:
@interface SEFSFormEditingViewController : UITableViewController
- (void) showSomething;
@end
在 myViewController.m 中我有:
-(void)showSomething:(UIButton *)sender
{
if (sender.tag == 0) {
NSString* test= @"test";
}
}
当我运行应用程序时,按钮会正确显示,但当我点击它时,应用程序会崩溃。
有人可以指出解决此问题的正确方向吗?
最佳答案
替换您的以下代码行
[button addTarget:self action:@selector(showSomething) forControlEvents:UIControlEventTouchUpInside];
与
[button addTarget:self action:@selector(showSomething:) forControlEvents:UIControlEventTouchUpInside];
关于ios - 尝试处理来自 UITableView 单元格中 UIButton 的点击事件会导致无效的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40083759/