I would want to show the image to from the directory. In the directory I have made folders to store the pictures. I am getting an error that is saying Use of undeclared identifier 'NSFileManagerdefaultManager' and Use of undeclared identifier 'documentsDirectory'; did you mean 'NSDocumentDirectory'? and Bad receiver type 'NSUInteger' (aka 'unsigned int'). I can not get rid of this. I am trying but it just doesn't work.

-(void)viewDidLoad
{
    [super viewDidLoad];

    //configure carousel
    imageArray1 = (NSMutableArray *)[[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    NSString *location=@"Tops";
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
    NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    imageArray1 = [directoryContent mutableCopy];

    imageArray2 = [[NSMutableArray alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    location=@"Bottoms";
    fPath = [documentsDirectory stringByAppendingPathComponent:location];

    directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
    imageArray2 = [directoryContent mutableCopy];

    carousel1.type = iCarouselTypeLinear;
    carousel2.type = iCarouselTypeLinear;
}
有帮助吗?

解决方案

There are some really wierd things in your code:

imageArray1 = (NSMutableArray *)[[NSFileManager defaultManager] directoryContentsAtPath: fPath];

Here you are casting an NSArray to a NSMutableArray, but it will still be an NSArray. You can't do this.

NSString *location=@"Tops";
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
imageArray1 = [directoryContent mutableCopy];

Then you build the fpath string, which you where already using the first line. Here you are doing the the conversion to NSMutableArray correctly.

You just need to remove the first line, it is not needed and does nothing. Same goes for this line:

imageArray2 = [[NSMutableArray alloc] init];

You are just create an empty array and then later you just assign an other array:

imageArray2 = [directoryContent mutableCopy];

Just remove the imageArray2 = [[NSMutableArray alloc] init]; it is not necessary and will only use unnecessary memory.

This will work better:

-(void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSFileManager *fileManager  = [NSFileManager defaultManager];

    //configure carousel
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:@"Tops"];
    NSArray *directoryContent = [fileManager directoryContentsAtPath: fPath];
    imageArray1 = [directoryContent mutableCopy];

    //configure carouse2
    fPath = [documentsDirectory stringByAppendingPathComponent:@"Bottoms";];
    directoryContent = [fileManager directoryContentsAtPath:fPath];
    imageArray2 = [directoryContent mutableCopy];

    carousel1.type = iCarouselTypeLinear;
    carousel2.type = iCarouselTypeLinear;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top