0

我有一个 UICollectionViewController 并且已经在单元格中显示了图像,当我单击/点击特定图像时,它会“推送”到普通的 ViewController。我怎么做?这是我到目前为止的代码......想在其他视图控制器中打开选定的图像,请帮助

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [imagearray count];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"Cell" ;
    customcell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    [[cell nyimage]setImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.item]]];
    return cell;

}
4

1 回答 1

2

您可以像这样实现委托方法:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController* viewController = [[DetailViewController alloc] init];
    //configure detail view controller
    // viewController.detailInfo = ...
    [self.navigationController pushViewController:viewController animated:YES];
}
于 2013-03-02T15:53:36.217 回答