UICollectionView不显示图像

时间:2015-01-20 20:24:58

标签: ios objective-c iphone xcode uicollectionview

我正在创建从手机相机胶卷中选择的一系列图像。它们被存储但由于某种原因我不能让它们显示在我的collectionView中。

在我的CollectionViewController.m

- (void)viewDidLoad {

    [self.photoCollectionView registerClass:[PhotoCell class] forCellWithReuseIdentifier:@"PhotoCell"];

    self.assets = [[NSMutableArray alloc]init];

    [super viewDidLoad];



- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.assets.count;
}

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCell *cell = (PhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath];

    ALAsset *asset = self.assets[indexPath.row];
    cell.asset = asset;
    cell.backgroundColor = [UIColor redColor];

    return cell;

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];


NSMutableArray *tmpAssets = [@[] mutableCopy];

[tmpAssets addObject:image];

self.assets = tmpAssets;

self.testImage.image = [self.assets objectAtIndex:0];

[picker dismissViewControllerAnimated:YES completion:Nil];

[self.photoCollectionView reloadData];

}

在我的PhotoCell.h课程中

@interface PhotoCell : UICollectionViewCell

@property (nonatomic,strong) ALAsset *asset;

@end

在我的PhotoCell.m课程中

#import "PhotoCell.h"

@interface PhotoCell ()

@property(nonatomic, strong) IBOutlet UIImageView *photoImageView;

@end

@implementation PhotoCell

- (void) setAsset:(ALAsset *)asset
{
    _asset = asset;
    self.photoImageView.image = [UIImage imageWithCGImage:[asset thumbnail]];
}
@end

任何帮助都会非常感谢你。

0 个答案:

没有答案