-5

我想计数而不是 long 但是它不起作用这是我的代码

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *locations = @[ @"Bottoms", @"Dress", @"Coats", @"Others", @"hats", @"Tops" ];
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:locations];
NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath];
collectionTrash.delegate =self;
collectionTrash.dataSource=self;
for(NSString *str in directoryContent){
    NSLog(@"i");
    NSString *finalFilePath = [fPath stringByAppendingPathComponent:str];
    NSData *data = [NSData dataWithContentsOfFile:finalFilePath];
    if(data)
    {
        UIImage *image = [UIImage imageWithData:data];
        [allImagesArray addObject:image];
        NSLog(@"array:%@",[allImagesArray description]);
    }}
for(NSString *folder in locations) {

    // get the folder contents

    for(NSString *file in directoryContent) {

        // load the image

    }
}}

我在 fpath 行中的位置出现错误。这是说不兼容的指针类型将 NSArray 强发送到 NSString 的参数。我怎样才能摆脱这个警告?通过研究,我在长度方面做错了。我应该怎么做才能让一切顺利?这是编译器警告

2013-08-25 16:21:28.890 [1899:907] -[__NSArrayI length]: unrecognized selector sent to 

    instance 0x1d5458c0
    2013-08-25 16:21:28.893 [1899:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x1d5458c0'  
    *** First throw call stack:
    (0x32c8b2a3 0x3a96f97f 0x32c8ee07 0x32c8d531 0x32be4f68 0x334fc8c9 0x89ee7 0x34ab2595 0x34b3e353 0x34b7fd11 0x34b7efe7 0x34ca13ef 0x34b7e0c5 0x34b7e077 0x34b7e055 0x34b7d90b 0x34b7de01 0x34aa65f1 0x34a93801 0x34a9311b 0x3679a5a3 0x3679a1d3 0x32c60173 0x32c60117 0x32c5ef99 0x32bd1ebd 0x32bd1d49 0x367992eb 0x34ae7301 0x89c35 0x3ada6b20)
    libc++abi.dylib: terminate called throwing an exception
    (lldb)

随意询问您是否想查看更多代码

4

1 回答 1

1

试试下面的代码而不是第 4 行。

NSString *fPath = documentsDirectory;
for(NSString *component in locations)
{
    fPath = [fPath stringByAppendingPathComponent:component];
}
于 2013-08-26T09:52:12.697 回答