Reputation: 2466
Here is how my project works, I have a UIScrollView
below it is a button addButton
, when clicked redirects you to the AGImagePickerController
(For those who doesn't know AGImagePickerController,it is a multiple image picker). Then you clicked the images(single or multiple images). When you press DONE
, it will save the images in NSCachesDirectory
. It will show the image chosen in UIScrollView
(Which can be deleted). When you pressed the addButton
again, it will show you the image picked
a while ago with a checkMark
.
PROBLEM : When I delete the image in the UIScrollView
the image that was deleted in the AGimagePickerController
is still checked
. Needed is when deleted in the UIScrollVIew
will also be remove in the AGimagePickerController
.
What I wanted to do is, save its image by its URL
then put it in a folder inside my NSCachesDirectory
so I can load it easily, but I dont know where to start, since Im arranging my images in the UIScrollView
by names with integers. Hope someone could suggest what to do. Thankyou Very Much.
NOTE : To those who have read this, please comment on what part of the code you want me to post here, or the part on which your having a problem with. Thankyou again.
CODE:
Here is my DONE
part:
for (int i = 0; i < info.count; i++) {
//NSLog(@"%@", [info objectAtIndex:i]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask ,YES );
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"oneSlotImages%u.png", i]];
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
//----resize the images
image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)];
//----fix image orientation
image = [image fixSlotOrientation];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
}
Then in my AGIPCAssetsController.m
(Where the retaining of the image checkmark
part)
- (void)loadAssets
{
count = 0;
[self.assets removeAllObjects];
AGIPCAssetsController *blockSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Where I make an array to put the `ALAsset Url`
selectedPhotos = [[NSMutableArray alloc] initWithArray:blockSelf.imagePickerController.selection];
@autoreleasepool {
[blockSelf.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
// ALAssetRepresentation* representation = [result defaultRepresentation];
// NSUInteger assetindex= [blockSelf.assetsGroup numberOfAssets];
if (result == nil)
{
return;
}
AGIPCGridItem *gridItem = [[AGIPCGridItem alloc] initWithAsset:result andDelegate:blockSelf];
if(count < blockSelf.imagePickerController.selection.count)
{
if ( blockSelf.imagePickerController.selection != nil &&
[result isEqual:[selectedPhotos objectAtIndex:count]])
{
gridItem.selected = YES;
count++;
NSLog(@" %@",result);
}
}
[blockSelf.assets addObject:gridItem];
}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[blockSelf reloadData];
});
});
}
Upvotes: 2
Views: 435
Reputation: 23278
Just an idea and not an exact solution. On Done button action, is it possible to save the image with name as some unique property of rep
. Probably [rep filename]
or [rep url]
can be used as image name while saving in place of @"oneSlotImages%u.png"
. And in loadAssets
read all the images stored in cache and compare its file name against the file names of images in selectedPhotos
and remove it from the selectedPhotos
array if it is not present in cache.
Upvotes: 1
Reputation: 1159
i think cause both of them have the same variable reference , check your variable reference and compare between both and let me know what u found .
Upvotes: 1