Hi Iam working with Iphone Photo Library. I got all photos from photo library with AssetFramework. I displayed those photos in scrollview and are perfectly displaying and images count is assume 6. Then when iam clicking single image, it will show large image. it is also done. my problem is "count is 12 (double count) when clicking image to show it as large."
I used below code to get images:
- (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);
}
}
Please notice that i created button and action is userImageClicked in above method. when iam clicking userImageClicked button, the array count is double.
i dont know why this is happened. i try to remove duplicates using containsObject method. but no use.
In above method, I saved UIImage
in objectclass
and assinging that object to imagesArray
.
I also took NSMutableSet
to store value, but it is also no use.
Please any one can suggest to solve my issue.