UITableViewCell添加控件注意事项

我们自定义了UITbleViewCell的基类,我们又盖了一层UIView,用于放我们的控件,我们做法如下:

UIView *_container = [[UIView alloc] init];
_container.backgroundColor = kColor_White;
[self addSubview:_container] ;
_container.sd_layout.leftSpaceToView(self, 0).topSpaceToView(self, 0).bottomSpaceToView(self, 0).rightSpaceToView(self, 0) ;

这样做,我们在container上添加了按钮,点击事件不起作用。
经过查看视频继承的关系,我们发现,UITablviewCell本身的contentView覆盖在了我们的_container之上

所以我们不要再自定义一个底UIView,直接使用它本身的contentView即可。

暂无评论

相关推荐

获取UIImage的尺寸

int contentWid = self.view.width ; unsigned long width = CGImageGetWidth(image.CGImage) ; unsigned long height …

微信扫一扫,分享到朋友圈

UITableViewCell添加控件注意事项