UITableViewCellにaddSubviewしたUIButtonがタップしても反応してくれなかった
原因は単純だったしたいした事じゃなかったんですけどとりあえずなんでも気づいたらoutputしようと思ったのでメモ。
CustomCell.m
@property (nonatomic) UIButton *button
~略~
- (void) hoge{
self.button.frame = CGRectMake(CGRectGetWidth(self.contentView.frame) - 20,
10 //適当
15,
15);
UIImageView *buttonImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hoge.png"]] ;
buttonImage.frame = CGRectMake(0,0,15,15);
[UIButton addSubview:buttonImage];
[self.contentView addSubview:button]
}
適当だけど上記みたいに。
- (void) hoge{
self.button.frame = CGRectMake(CGRectGetWidth(self.contentView.frame) - 20,
10 //適当
25, //ボタン範囲を広げた
25 //ボタン範囲を広げた
);
UIImageView *buttonImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]] ;
buttonImage.frame = CGRectMake(0,0,15,15);
[UIButton addSubview:buttonImage];
[self.contentView addSubview:button]
}
- ButtonをbringSubviewToFrontしたりとか、
- [self.contentView setUserInteractionEnabled: NO]したりとか、
- 親ビューからボタンがはみ出してないかとか、