0

我正在使用此代码来回忆我为每种类型创建的目录。但是,我在“[arrayCollectionImages addObject:image];你能解释一下最后一段代码有什么问题”的图像部分出现错误。我在 arrayCollectionImages 也有一个警告,说 arrayCollectionImages 的本地声明隐藏实例变量。它还告诉我 [[cell collectionImageView]setImage:[UIImage imageNamed:[arrayCollectionImages objectAtindex:indexPath.item]]];“NSArray”的 No visible @interface 声明了选择器“objectAtindex:;” 我做错了什么?

#import "CollectionViewController.h"
#import "CollectionCell.h"



@interface CollectionViewController (){
    NSArray *arrayCollectionImages;
}


@end

@implementation CollectionViewController

- (void)viewDidLoad {
    NSArray *allImagesArray = [[NSArray alloc ]init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *location=@"Genre1";
    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)
        {
            UIImage *image = [UIImage imageWithData:data];
            [allImagesArray addObject:image];
        }
    }

    [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

这是我保存到目录的代码

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    FrontCamera = NO;
    cameraSwitch.selectedSegmentIndex = 1;
    captureImage.hidden = YES;

     [pickerViewContainer addSubview:SaveTopicker];

    arraygenre = [[NSMutableArray alloc] init];
    [arraygenre addObject:@"Tops"];
    [arraygenre addObject:@"Pants"];
    [arraygenre addObject:@"Coats"];
    [arraygenre addObject:@"Shoes"];
    [arraygenre addObject:@"Hats"];
    [arraygenre addObject:@"Others"];
    pickerViewContainer.frame = CGRectMake(0, 800, 320, 261);


}


- (void)viewDidAppear:(BOOL)animated {
    [self initializeCamera];
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    //fetch Category Name from the array used to fill the Picker View
    NSString *categoryName= [arraygenre objectAtIndex:row];
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:categoryName];
    NSFileManager *fileManager=[[NSFileManager alloc]init];
    [fileManager createDirectoryAtPath:fPath withIntermediateDirectories:YES attributes:nil error:nil];

    UIImage *image = captureImage.image;
    NSData *data = UIImagePNGRepresentation(image);
    [data writeToFile:fPath atomically:YES];

}
4

1 回答 1

0

方法名称是 objectAtIndex:。方法名称中的“i”是小写的,这是不正确的。

于 2013-08-14T14:39:58.063 回答