如何使用特定项初始化uicollectionview(indexPath)

时间:2013-09-18 10:44:22

标签: ios objective-c

我在firstViewController上有一个好看的gridView,并且在SecondViewController上也有UIcollectionview,现在我的问题是,如果我在GridView中选择第四项,那么Collectionview应该显示零项目的第四项内容(现在的集合视图是显示从第0个索引)!

我的didSelectItemAtIndexPath:在FirstViewController上,这里我得到了传递给secondviewcontroller的NSInteger值,

- (void)gridView:(KKGridView *)theGridView didSelectItemAtIndexPath:(KKIndexPath *)indexPath
{
   NSInteger globalIndex = ( indexPath.section * numberOfThumbnails ) + indexPath.index;
..............................
}

我的cellForItemAtIndexPath:在secondViewController上,

(UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{

    itemData =[DataArray objectAtIndex:indexPath.row];

    NSString *finalPath = [FileUtils findImagePath:[itemData filename]];

    CollectionCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];


    [cell.imageView setImage:[UIImage imageWithContentsOfFile:finalPath]];

    }

1 个答案:

答案 0 :(得分:1)

您需要做的是使用

滚动到该特定项目
 scrollToItemAtIndexPath:atScrollPosition:animated:  

或选择该项目

 selectItemAtIndexPath:animated:scrollPosition: