我如何引用一个特定的UICollectionViewCell,以便每个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标记到17 1VC的单元格。
是这样的吗:
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];
}发布于 2014-02-19 15:20:41
您需要在您的集合视图控制器(而不是单元格)和目标控制器之间建立分隔符,为每个人提供一个唯一的故事板ID。
然后,在collectionView:didSelectItemAtIndexPath:委托方法中,根据indexPath决定要对哪个控制器进行分割,并以编程方式启动segue:
- (void)collectionView:collectionView didSelectItemAtIndexPath:indexPath
{
NSString *storyboardId = ...; // determine storyboard ID based on indexPath
[self performSegueWithIdentifier:storyboardId sender:indexPath];
}https://stackoverflow.com/questions/21864695
复制相似问题