0

セルに ImageViews を使用して CollectionView を実装しました。セルがタップされたときに DetailViewController が表示されるようにします。ImageView と Cell の Interface Builder で User Interaction Enabled を設定しました。私は何を間違えていますか?ViewController に次のコードがあります。

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
    return 9;
}

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

    PhotosCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];



    // load the image for this cell
    NSString *imageToLoad = [NSString stringWithFormat:@"%d.jpg", indexPath.row +1];
    // NSLog(imageToLoad);
    cell.imageView.image = [UIImage imageNamed:imageToLoad];

    return cell;
}

// the user tapped a collection item, load and set the image on the detail view controller
//
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   // NSLog(@"inside!");
    if ([[segue identifier] isEqualToString:@"showDetail"])
    {
        NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];

        // load the image, to prevent it from being cached we use 'initWithContentsOfFile'
        NSString *imageNameToLoad = [NSString stringWithFormat:@"%d_full", selectedIndexPath.row+1];
        NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:@".jpg"];
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];

        PhotoDetailViewController *detailViewController = [segue destinationViewController];
        detailViewController.myImage = image;
    }
}

しかし、セルがタップされたときにメソッド「prepareForSegue」が呼び出されていません...

4

1 に答える 1