如何将Count放入以便它不会有警告

时间:2013-08-26 09:41:26

标签: ios arrays directory warnings

我想把一个计数而不是很长但是它不起作用这是我的代码

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参数。我怎么能摆脱这个警告?通过reaserch我做了一些错误的长度。我该怎么办才能让一切顺利?这是编译器警告

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)

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

1 个答案:

答案 0 :(得分:1)

尝试以下代码而不是第4行。

NSString *fPath = documentsDirectory;
for(NSString *component in locations)
{
    fPath = [fPath stringByAppendingPathComponent:component];
}