【发布时间】:2014-02-18 20:33:54
【问题描述】:
我如何引用特定的UICollectionViewCell,以便他们每个人都转到不同的 VC?
这是单元格的代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:self.myCellImages[0]];
UIImage *cellImage = [[UIImage alloc] init];
cellImage = [UIImage imageNamed:[self.myCellImages objectAtIndex:indexPath.row]];
cell.imageView.image = cellImage;
return cell;
}
因此,这会根据我加载到数组中的图像数量显示一堆不同的单元格。
说我的数组是:
self.myCellImages = @[@"1.jpg", @"2.jpg",.... @"20.jpg"];
我如何引用一个单独的单元格,以便它进入不同的 VC?例如,单击具有图像 1.jpg segues 的单元格进入 1VC,然后单击具有 17.jpg 的单元格进入 17VC
是不是类似于:
if (NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];)
{
//segue here
}
我不知道正确的语法
感谢蒂莫西,我添加了
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:indexPath
{
NSString *storyboardId = @"main_to_VC1";
[self performSegueWithIdentifier:storyboardId sender:indexPath];
}
【问题讨论】:
标签: objective-c uicollectionview uistoryboard uicollectionviewcell nsindexpath