안녕하세요, 아이폰 사진 라이브러리와 협력하고 있습니다. AssetFramework로 사진 라이브러리에서 모든 사진을 받았습니다. 내가 그 사진을 scrollview에 표시하고 완벽하게 표시하고 이미지 개수가 가정합니다 6. 다음 iam 단일 이미지를 클릭하면 큰 이미지가 표시됩니다. 그것은 또한 행해진 다. 내 문제는 "개수가 12 (두 번 카운트) 이미지를 클릭하면 대형으로 표시됩니다."nsmutableArray에서 중복 데이터를 제거하는 방법
나는 이미지를 얻을 코드 아래 사용 :
- (void)createScrollView
{
@try
{
NSLog(@"in create scrollview");
//add views to scrolview
// UIImageView *backgroundImgView;
int x=5;
int y=7;
NSLog(@"assetsArray/count/createScrollview %d",assetsArray.count);
for (int i=0;i<[assetsArray count];i++)
{
UIView *userView=[[UIView alloc] initWithFrame:CGRectMake(x, y, 70, 80)];
userView.tag=i;
UIImageView *backgroundImgView=[[UIImageView alloc] initWithFrame:CGRectMake(1, 1, 70, 70)];
backgroundImgView.tag=1;
// [backgroundImgView setImageWithURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF16BigEndianStringEncoding]] placeholderImage:[UIImage imageNamed:@"NoImage.png"]];
//-------------Getting Images from AssetsLibrary ----------
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
galleryObj=[[GalleryObject alloc]init];
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *assetsLibraryImage;
if (iref)
{
assetsLibraryImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
galleryObj.galleryImage=assetsLibraryImage;
}
else
{
assetsLibraryImage = [UIImage imageNamed:@"NoImage.png"];
}
//[set addObject:[NSString stringWithFormat:@"1"]];
[uniqueSet addObject:galleryObj];
NSLog(@"uniqueSet data is .....%@",uniqueSet); // Output (3,1,4,2,5) ... all objects
[imagesArray addObject:galleryObj];
NSLog(@"imagesArray/resultBlock count is %d array is %@....",imagesArray.count,imagesArray);
backgroundImgView.image=assetsLibraryImage;
};
ALAsset *al_asset = [assetsArray objectAtIndex:i];
//NSLog(@"al_asset is ......%@",al_asset);
al_assetUrl=al_asset.defaultRepresentation.url;
//NSLog(@"al_assetUrl is %@",al_assetUrl);
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"ALAssetsLibraryAccessFailureBlock");
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:al_assetUrl resultBlock:resultblock failureBlock:failureblock];
//-------------Getting Images from AssetsLibrary ----------
UIButton *userButton=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, 70,70)];
[userButton addTarget:self action:@selector(userImageClicked:) forControlEvents:UIControlEventTouchUpInside];
userButton.tag=i;
[userView addSubview:backgroundImgView];
[userView addSubview:userButton];
[self.galleryScrollview addSubview:userView];
x+=79;
if ((i+1)%4==0)
{
//if added image is 4th image
y+=80;
x=5;
}
// [activity stopAnimating];
}
if (y+100>self.galleryScrollview.frame.size.height)
{
self.galleryScrollview.contentSize=CGSizeMake(320, y+100);
}
else
{
self.galleryScrollview.contentSize=CGSizeMake(320, self.galleryScrollview.frame.size.height+60);
}
}
@catch (NSException *exception)
{
NSLog(@"exception is %@",exception);
}
}
내가 버튼을 생성하고 조치를 위의 방법에 userImageClicked 것을 알하시기 바랍니다. userImageClicked 버튼을 클릭하면 배열 수가 두 배가됩니다.
왜 이런 일이 발생했는지 알지 못합니다. 난 containsObject 메서드를 사용하여 중복을 제거하려고합니다. 그러나 아무 사용.
위의 방법에서는 UIImage
을 objectclass
에 저장하고 해당 개체를 imagesArray
으로 지정했습니다.
또한 값을 저장하기 위해 NSMutableSet
을 가져 갔지만 사용하지도 않았습니다.
제발 내 문제를 해결하기 위해 제안 할 수 있습니다.
NSMutableArray *unique = [NSMutableArray array];
for (id obj in originalArray) {
if (![unique containsObject:obj]) {
[unique addObject:obj];
}
}
*이 * 중복 데이터를 추가하지, 중복 데이터 *를 제거 잘못된 방향으로 작업하는 이유는 모든 자산 – Leena
*에 대한 고유을 AssetUrl 사용 확인에 작동합니다. – rptwsthi
Google 상위 5-6 ref.에 머리말 만 넣는 것처럼 자동 응답을하고 싶지 않습니다. SO에서 올거야. – Buntylm