문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top