首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionViewCell NSindexpath参考位置

UICollectionViewCell NSindexpath参考位置
EN

Stack Overflow用户
提问于 2014-02-18 20:33:54
回答 1查看 152关注 0票数 0

我如何引用一个特定的UICollectionViewCell,以便每个UICollectionViewCell都能转换成不同的VC?

这里是单元格的代码:

代码语言:javascript
复制
- (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;
}

因此,这将显示一组不同的单元格,这取决于加载到数组中的图像的数量。

说我的数组是:

代码语言:javascript
复制
 self.myCellImages = @[@"1.jpg", @"2.jpg",.... @"20.jpg"];

如何引用单个单元格,以便将其划分为不同的VC?例如,单击将图像1.jpg segues转换为1VC的单元格,然后单击带有17.jpg标记到17 1VC的单元格。

是这样的吗:

代码语言:javascript
复制
if (NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];)
{
//segue here
}

我找不出正确的语法

多亏了蒂莫西,我补充说

代码语言:javascript
复制
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:indexPath
{
    NSString *storyboardId = @"main_to_VC1"; 
    [self performSegueWithIdentifier:storyboardId sender:indexPath];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-19 15:20:41

您需要在您的集合视图控制器(而不是单元格)和目标控制器之间建立分隔符,为每个人提供一个唯一的故事板ID。

然后,在collectionView:didSelectItemAtIndexPath:委托方法中,根据indexPath决定要对哪个控制器进行分割,并以编程方式启动segue:

代码语言:javascript
复制
- (void)collectionView:collectionView didSelectItemAtIndexPath:indexPath
{
    NSString *storyboardId = ...; // determine storyboard ID based on indexPath
    [self performSegueWithIdentifier:storyboardId sender:indexPath];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21864695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档