我有一个UICollectionView,其单元全部布局。在UICollectionViewCell中点击一个UIButton
我有这个声明为一个子视图:
@property (nonatomic, strong) UIButton *aButton;
然后我有一个声明在每个单元中,像这样:
if (_aButton == nil)
{
_aButton = [UIButton buttonWithType:UIButtonTypeSystem];
}
// Add in all _aButton info here
[self.contentView addSubview:_aButton];
// Call to button pressed for button
[_aButton addTarget:self action:@selector(aButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
点击按钮的方法是像这样:
- (IBAction) aButtonPressed:(UIButton *) sender
{
// Code never gets heree
}
if(_aButton
==`nil)是需要的,因为单元格被重用。
现在该如何完成这项工作?谢谢。
究竟是什么错误?零检查与重用无关,除非您将按钮移到其他地方。 – Wain
为什么不使用故事板for collectionview与原型单元格?更好的方式来设置故事板上的按钮。 – merge
框架设置正确,并在//中添加所有aButton的东西 – cdub