collectionViewCell의 각 항목에있는 장치 갤러리에서 ALAssets 목록을 표시하는 데 문제가 있습니다.UICollectionViewController의 ALAssets에 이미지가 표시되지 않습니다.
내 이미지가 컬렉션보기에 표시되지 않습니다. 나는 친척 게시물에서 찾은 모든 해결책을 시도했지만 대답을 찾지 못했습니다 ... 왜? ARC & 스토리 보드를 사용하여
아이폰 5, IOS 6.0.2, 엑스 코드 4.5, :
여기 내 dev에 환경입니다.
#의 AppDelegate.m
-(void)loadPhotosFromDevice
{
//deviceMedia = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
// Within the group enumeration block, filter if necessary
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
{
// The end of the enumeration is signaled by asset == nil.
if (alAsset)
{
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
[self addPhoto:representation andAsset:alAsset];
}
else
{
//NSLog(@"Done! Count = %d", deviceMedia.count);
//Do something awesome
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
}
}
2 : 내 위임에 장치 미디어로 MutableArray를 가져
: 1. 먼저, 여기
그리고
내 코드입니다 . "Media"객체 클래스에 "AddPhoto"메서드를 사용하여 모든 데이터를 보냅니다.,210#의 AppDelegate.m
-(void)addPhoto:(ALAssetRepresentation *)asset andAsset:alAsset
{
//NSLog(@"Adding photo!");
Media *media = [[Media alloc] init];
media.baseurl = @"";
media.url = [asset.url absoluteString];
Thumbnail *t = [[Thumbnail alloc] init];
t.rep = asset;
t.url = [asset.url absoluteString];
media.thumbnails = [[Thumbnail alloc] initWithRepresentation:asset];
media.name = asset.filename;
media.asset = alAsset;
media.isFromDevice = YES;
[getPhotos addObject:media];
NSLog(@"\nDevice Photo added array");
}
# Media.h
import <AssetsLibrary/AssetsLibrary.h>
@interface Media : NSObject
{
//General
AudioInfo *audioInfo;
Info *info;
Header *header;
Status *requestStatus;
Exif *exif;
Thumbnail *thumbnails;
NSString *name;
NSString *uploaddt;
NSString *baseurl;
NSString *url;
NSString *createdt;
NSString *takendt;
NSString *recorddt;
ALAsset *asset;
bool isFromDevice;
}
//General
@property (nonatomic, retain) Thumbnail *thumbnails;
@property (nonatomic, retain) Status *requestStatus;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *uploaddt;
@property (nonatomic, retain) NSString *baseurl;
@property (nonatomic, retain) NSString *url;
@property (nonatomic, retain) NSString *createdt;
@property (nonatomic, retain) NSString *takendt;
@property (nonatomic, retain) NSString *recorddt;
@property (nonatomic, retain) ALAsset *asset;
@property (nonatomic, readwrite) bool isFromDevice;
@end
3. 그런 다음 나는 CollectionViewController에이를 표시 :
#PhotoDisplayCloudViewController
,@implementation PhotoDisplayCloudViewController
- (void)viewDidLoad {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
tableau = appDelegate.getPhotos;
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return tableau.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//CELL
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
Media *object = [[Media alloc] init];
object = [tableau objectAtIndex:indexPath.row];
//IMAGE
NSString *url = [NSString stringWithFormat:@"%@%@", object.baseurl, object.thumbnails.url];
NSLog(@"%@ start loading", object.name);
UIImageView *image = [[UIImageView alloc] init];
if (object.isFromDevice)
{
image = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage :[object.asset.self thumbnail]]];
}
else
{
image = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: url]]]];
}
[image setFrame:CGRectMake(image.frame.origin.x, image.frame.origin.y, 72, 72)];
//LABEL
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(image.frame.origin.x+6, image.frame.origin.y+58, 60, 12)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = UIColor.blackColor;
label.contentMode = UIViewContentModeBottom;
label.font = [UIFont fontWithName:@"Times New Roman" size:9];
label.text = object.name;
//ADD VIEWS
[cell addSubview:image];
[cell addSubview:label];
NSLog(@"%@ end loading", object.name);
return cell;
}
- (void)didGrabImage:(UIImage *)image {
[collectionCell addSubview:image];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
PhotoDetailViewController *photoDetailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"photoDetail"];
photoDetailViewController.MaPhoto=[tableau objectAtIndex:indexPath.row];
[self.navigationController pushViewController:photoDetailViewController animated:YES];
}
@end
나에게 명확 ^^
사전 들으 답변 해주세요! "adaydesign의 블로그"에
덕분에, 나는있는 UIImageView에 내 자산을로드하는 데이 방법을 사용 :
Xcode에 대해 질문하지 않은 것 같습니다. 그렇다면이 태그가 붙은 Xcode는 왜 그런가요? –
저는이 프로젝트를 개발하기 위해 XCode를 사용하고 있습니다. 그래서 XCode로 태그를 추가했습니다. 미안해 평소 아니라면 ... – user1903839