我正在创建产品目录,每个产品都是UICollectionViewCell
,其中包含titleLabel
,UIImage
和按钮。我想在触摸按钮时显示产品详细信息,但我不知道如何告诉每个产品属于哪个产品
答案 0 :(得分:0)
嗯,你必须实现UICollectionViewDelegate的方法并按索引传递相应的产品。
- (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];
}
假设您已声明产品的属性;
@property (nonatomic, strong) NSArray *products;
希望这有帮助。