我有一個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