【发布时间】:2014-02-14 06:42:01
【问题描述】:
这里我将核心数据与 UICollectionView 一起使用,每当我重新加载 CollectionView 时都会出现一些问题。
问题是,当我创建一个相册并在其上设置一张最新照片(如果存在任何照片,否则相册上没有图像设置),它是从实体“PHOTO”获取的,然后重新加载收藏视图,然后这张相册也在自身上设置图像(相册实际上是 CollectionViewCell)。
真的很烦人。如果有人能解决这个问题,请指导我。
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor yellowColor];
//Get Album Names
GMSAlbum *objAlbumEntity = [arrayAlbums objectAtIndex:indexPath.row];
NSLog(@"AlbumName = %@",objAlbumEntity.name);
delegate->currentAlbum = [arrayAlbums objectAtIndex:indexPath.row];
//NSLog(@"current path = %@",delegate->currentAlbum);
//Get Last image
NSString *imagePath = [self getLastImage:delegate->currentAlbum];
NSLog(@"Image Path = %@",imagePath);
if (![imagePath isEqualToString:@""]) {
UIImageView *imageThumb = [[UIImageView alloc] initWithFrame:
CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[imageThumb setImage:[UIImage imageWithContentsOfFile:imagePath]];
[cell addSubview:imageThumb];
}
return cell;
}
-(NSString *)getLastImage:(Album *)album{
NSString *imagePath = @"";
GMSPhotoModel *objPhotoModel = [[GMSPhotoModel alloc] init];
NSMutableArray *arryPhotos = [objPhotoModel getAllPhotoForAlbum:album];
NSLog(@"Array count = %d",[arryPhotos count]);
if ([arryPhotos count]) {
GMSPhoto *objPhotoName = [arryPhotos lastObject];
imagePath = objPhotoName.path;
NSLog(@"Naming Album = %@",objPhotoName.name);
}
NSLog(@"Path = %@",imagePath);
return imagePath;
}
【问题讨论】:
-
说出你的要求……你不清楚……
-
为什么在重新加载数据时相册设置了图片而相册中没有照片
-
如果没有图像,您在 iPad 上查看/编辑 MS Word 文档会得到什么?
-
当我与相关相册合影时,没有任何图像路径是空的,但似乎每次都会发生单元格笔记上的图像但是发生了:(
-
是否进入 if 条件?
标签: ios objective-c core-data uicollectionview