Ios 单击自定义单元格中的UIButton后,不会收到任何事件

Ios 单击自定义单元格中的UIButton后,不会收到任何事件,ios,objective-c,uitableview,uibutton,Ios,Objective C,Uitableview,Uibutton,我有一个自定义单元格,它是UITableViewCell的子类。我在自定义单元格中为按钮添加了一个单击事件,但单击按钮后什么也没有发生 我的代码基本上如下所示: MyCustomCell.h: @interface MyCustomCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIButton *thumbnailButton; @property (weak, nonatomic) IBOutlet UILabel *t

我有一个自定义单元格,它是UITableViewCell的子类。我在自定义单元格中为按钮添加了一个单击事件,但单击按钮后什么也没有发生

我的代码基本上如下所示:

MyCustomCell.h:

@interface MyCustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *thumbnailButton;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
// bla bla...
@end
MyTableViewController.h:

@interface MyTableViewController : UITableViewController
// bla bla...
- (void)thumbnailButtonClicked:(UIButton *)sender;
// bla bla...
@end
MyTableViewController.m:

#import "MyTableViewController.h"
#import "MyCustomCell.h"

// bla bla...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"MyCustomCell";
    MyCustomCell *cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    [cell.contentView setUserInteractionEnabled:NO];
    [cell.thumbnailButton addTarget:self 
                             action:@selector(thumbnailButtonClicked:)  
                   forControlEvents:UIControlEventTouchUpInside];
    cell.thumbnailButton.tag = indexPath.row;

    return cell;
}

- (void)thumbnailButtonClicked:(UIButton *)sender
{
    NSLog(@"[%d] Button Clicked!", sender.tag);
}
上面的thumbnailButton的坐标为7、6、100、66,不超过其父帧


谁能告诉我怎么解决这个问题吗?我已经为此挣扎了一段时间…

可能是因为您将contentView的userInteractionEnabled设置为NO?1您的tableView委托设置正确吗?CellForRowatingIndexPath中的其余代码是否已调用?2也许您已经为tableView单元格设置了cancelsTouchesInView=NO?编写的代码将在每次重新使用单元格时持续向单元格的缩略图按钮添加操作。另外,检查cell.thumbnailButton是否为零。可能您没有连接nib中的视图。[cell.contentView setUserInteractionEnabled:否];按钮是一个子视图,因此点击将不会在自定义单元格的.m文件中传递您为创建按钮而编写的内容。。。?