【发布时间】:2012-10-01 08:46:26
【问题描述】:
这是我的项目的工作方式,我有一个UIScrollView,它下面是一个按钮addButton,单击时会将您重定向到AGImagePickerController(对于那些不知道AGImagePickerController的人,它是一个多图像选择器)。然后单击图像(单个或多个图像)。当您按下DONE 时,它会将图像保存在NSCachesDirectory 中。它将显示在UIScrollView 中选择的图像(可以删除)。当您再次按下addButton 时,它会向您显示不久前的图像picked 和checkMark。
问题:当我删除UIScrollView 中的图像时,AGimagePickerController 中删除的图像仍然是checked。需要的是在UIScrollVIew 中删除时也将在AGimagePickerController 中删除。
我想做的是,通过它的URL 保存它的图像,然后将它放在我的NSCachesDirectory 内的一个文件夹中,这样我就可以轻松加载它,但我不知道从哪里开始,因为我将我的图像安排在UIScrollView 名称为整数。希望有人可以建议该怎么做。非常感谢。
注意:对于阅读过本文的人,请评论您希望我在此处发布的代码的哪一部分,或者您遇到问题的部分。再次感谢您。
代码:
这是我的DONE 部分:
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];
}
然后在我的AGIPCAssetsController.m(其中保留了图片checkmark的部分)
- (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];
});
});
}
【问题讨论】:
标签: iphone objective-c ios xcode