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

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top