0

UICollectionViewController があり、特定の画像をクリック/タップすると、通常の ViewController に「プッシュ」されるため、既にセルに画像が表示されています。それ、どうやったら出来るの?ここに私がこれまでに持っているコードがあります...選択した画像を他のView Controllerで開きたいのですが、助けてください

-(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 に答える