Question

I am creating a catalog of products, and every product is an UICollectionViewCell with a titleLabel, an UIImage and a button. I want to show the product details when the button is touched but I don't know how to tell to every cell which product belongs

Était-ce utile?

La solution

Well, you have to implement UICollectionViewDelegate's method and pass corresponding product by index.

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    Product *selectedProduct = self.products[indexPath.row];
    DetailsViewController *detailsVC = [[DetailsViewController alloc] initWithProduct:selectedProduct];
    [self.navigationController pushViewController:detailsVC animated:YES];
}

assuming you have declared property for your products;

@property (nonatomic, strong) NSArray *products;

Hope this helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top