【发布时间】:2014-02-24 19:47:30
【问题描述】:
我有一个 UICollectionView,我无法将图像传输到详细视图。当我使用本地图像和带有 [pictures[row]] 方法的图片数组时,detailview 传输将起作用,但由于使用 SDWebImage 框架,我不能这样做。选择单元格后,我无法确定将图像正确传输到详细视图。逻辑在第一个方法 CellForItemAtIndexPath 中解释。选定的单元格和为 segue 方法做准备是导致问题的原因。如果您需要更多信息,请告诉我。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
pictureViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];
comment = [[pictures objectAtIndex:indexPath.row] objectForKey:@"comment"];
[cell.imageView setImageWithURL:[NSURL URLWithString:pictures1]
placeholderImage:[UIImage imageNamed:@"Earth.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
NSLog(@"Error downloaidng images");
}];
// UIImage *image;
// int row = [indexPath row];
//image = [UIImage imageNamed:pictures[row]];
//image = [UIImage imageWithData:imageUrl];
// cell.imageView.image = image;
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image;
//int row = [indexPath row];
NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];
// image = [UIImage imageNamed:pictures[row]];
image = [UIImage imageNamed:pictures1];
pictureDetailView *pictureDetail = [[pictureDetailView alloc]init];
pictureDetail.image = image;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UICollectionViewCell *)sender
{
pictureDetailView *targetVC = (pictureDetailView *) [segue destinationViewController];
NSIndexPath *indexPath = [self.collectionView indexPathForCell:sender];
UIImage *image;
//int row = [indexPath row];
NSString *pictures1 = [[pictures objectAtIndex:indexPath.row]objectForKey:@"filename"];
// image = [UIImage imageNamed:pictures[row]];
image = [UIImage imageNamed:pictures1];
//image = [UIImage imageWithData:imageUrl];
targetVC.image=image;
}
@end
【问题讨论】:
标签: ios objective-c json storyboard uicollectionview