Ich habe eine Schaltfläche auf der collectionviewcell
hinzugefügt, und sobald Benutzer auf diese Schaltfläche klickt, ruft es die folgende Methode, aber uviCollectionViewCell
gibt Null zurück. gleich OhrenmarkeZugriff auf CollectionViewCell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(collectionView == productCollectionView)
{
__weak ProductCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.addBtnOutlet.tag = indexPath.row;
[cell.addBtnOutlet addTarget:self
action:@selector(collectionViewCellAddButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
- (IBAction)collectionViewCellAddButtonPressed:(UIButton *)button{
NSLog(@"Add Button Clicked");
// the following is nil
UICollectionViewCell *uviCollectionCell = [self.productCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathWithIndex:0]];
}
[NSIndexPath indexPathForRow: button.tag insection: 0] für vollständige Code '[self.productCollectionView cellForItemAtIndexPath: [NSIndexPath indexPathForRow: button.tag insection: 0 ]]; ' –
@ anbu-carthik: Danke für die Bearbeitung der Antwort Ich habe Ihre Bearbeitung beibehalten, während ich nicht sicher bin, was OP Anforderung ist daher eine Notiz so gut gehalten –
@ Anbu.Karthik, vielen Dank, es hat funktioniert. Ich habe den Abschnitt nicht hinzugefügt, ich dachte, wenn ich es nicht aufstelle, wird es Null als Standard zuweisen. Bitte geben Sie Ihren Code als Antwort ein und ich werde ihn akzeptieren. – hotspring