我正在做一些涉及其中包含照片的集合视图,并且在选择其中一个单元格时,它将进入一个显示更大图像的新视图。
继承人为segue做准备
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"showPhotoSegue"]) {
NSIndexPath *ip = [self.photoCollectionView indexPathForCell:sender];
PhotoDisplayViewController *viewController = segue.destinationViewController;
Photo* photo = [self.fetchedResultsController objectAtIndexPath:ip];
NSLog(@"setting PHOTO at indexPath %@", ip);
[viewController setPhoto:[UIImage imageWithContentsOfFile:photo.url]];
}
}
继承人 didSelectItemAtIndexPath
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier = @"showPhotoSegue";
[self performSegueWithIdentifier:identifier sender:self];
NSLog(@"Selected item at %@", indexPath);
}
我的视图总是空的,所以我添加了打印行语句,看起来输出总是像
Selected cell at <NSIndexPath 0x1e084940> 2 indexes [0, 0], detail view controller
所以我的问题是,为什么 NSIndexPath 总是一对 2 索引,以及如何在我的 prepareforsegue 中使用它来设置 segue 的视图
谢谢