如何通过触摸UICollectionViewCell显示详细数据?

时间:2014-05-05 14:23:44

标签: ios uicollectionview uicollectionviewcell

我正在创建产品目录,每个产品都是UICollectionViewCell,其中包含titleLabelUIImage和按钮。我想在触摸按钮时显示产品详细信息,但我不知道如何告诉每个产品属于哪个产品

1 个答案:

答案 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;

希望这有帮助。