[英]UICollectionViewCell is not showing DetailView when tapped
I implemented a CollectionView with ImageViews in the cells. 我在单元格中实现了具有ImageViews的CollectionView。 I want a DetailViewController to appear when the cell is tapped.
我希望在轻按单元格时出现一个DetailViewController。 I set the User Interaction Enabled in the Interface Builder for the ImageView and the Cell.
我在“界面生成器”中为ImageView和单元设置了“启用用户交互”。 What am I making wrong?
我做错了什么? I have this code in the ViewController:
我在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;
}
}
But the method "prepareForSegue" is not being called when the cell is tapped... 但是,在点击单元格时不会调用方法“ prepareForSegue”。
implement collectionview delegate method 实现collectionview委托方法
collectionView:didSelectItemAtIndexPath:
there call 有电话
[self performSegueWithIdentifier:@"showDetail" sender:self];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.