我想保存显示在UIImage
. 但是我想将其分类为类型,例如蔬菜、肉类、生菜等。
我找不到办法做到这一点。
最好和最简单的方法是什么?
此外,我想让用户使用选择器控制器选择他想要保存的类别来保存。谢谢!我真的需要帮助!!
更新 2
为了检查它是否已保存,我进一步构建了一个集合视图控制器,但在[arrayCollectionImages addObject:image];
你能解释一下最后一段代码的图像部分出现错误。我在 arrayCollectionImages 也有一个警告,说 arrayCollectionImages 的本地声明隐藏实例变量。——</p>
@interface CollectionViewController (){
NSArray *arrayCollectionImages;
}
@end
@implementation CollectionViewController
- (void)viewDidLoad {
dispatch_queue_t searchQ = dispatch_queue_create("com.awesome", 0);
dispatch_async(searchQ, ^{
NSArray *arrayCollectionImages = [[NSArray alloc ]init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *location=@"Hats";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
for(NSString *str in directoryContent){
NSString *finalFilePath = [fPath stringByAppendingPathComponent:str];
NSData *data = [NSData dataWithContentsOfFile:finalFilePath];
if(data)
{ dispatch_async(dispatch_get_main_queue(),^{
UIImage *image = [UIImage imageWithData:data];
});
[arrayCollectionImages addObject:images];
}
}
});
[super viewDidLoad];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ReuseID" forIndexPath:indexPath];
[[cell collectionImageView]setImage:[UIImage imageNamed:[arrayCollectionImages objectAtindex:indexPath.item]]];
return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [arrayCollectionImages count];
}
@end