- [NSPathStore2 objectForKey:]:无法识别的选择器发送到实例0x6a3fc60'

时间:2010-11-15 15:03:44

标签: iphone uitableview

我正准备在tableView中使用customCellView。据我所知,.xib和方法都很完美。我在配置单元格时遇到异常。

int listIndex = [indexPath indexAtPosition:[indexPath length] - 1];
    NSLog(@"outside");          
    cell.lblName.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:@"filesName"];
    cell.lblSize.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:@"filesSize"];
    cell.lblType.text = (NSString *) [[directoryContent objectAtIndex:listIndex] objectForKey:@"filesType"];
    return cell;

编译器一直工作到NSLog(@"outside");。但它没有进入下一行。我被错误

终止了
2010-11-15 20:32:28.623 iDataTraveller[5346:207] outside
2010-11-15 20:32:28.625 iDataTraveller[5346:207] -[NSPathStore2 objectForKey:]: unrecognized selector sent to instance 0x5f19cf0
2010-11-15 20:32:28.627 iDataTraveller[5346:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPathStore2 objectForKey:]: unrecognized selector sent to instance 0x5f19cf0'

请帮我继续..提前谢谢..

3 个答案:

答案 0 :(得分:3)

无论您在何处创建了directoryContent,都会将错误的对象存储在其中 NSPathStore2是在NSString上使用stringByAppendingPathComponent:之类的东西时创建的对象。
我想你只是将文件名存储在数组中,但想存储从NSFileManagers创建的NSDictionary attributesOfItemAtPath:error:

检查那部分是否再次向directoryContent添加对象。

答案 1 :(得分:1)

这是我的代码。看看这个。让我知道我在滞后。

- (void)listFiles {

    NSFileManager *fm =[NSFileManager defaultManager];
    NSError *error = nil;
    NSString *parentDirectory = @"/Users/akilan/Documents";
    NSArray *paths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error];
    if (error) {
        NSLog(@"%@", [error localizedDescription]);
        error = nil;
    }
    NSMutableArray *array = [[NSMutableArray alloc] init];
    self.directoryContent = array;
    [array release];

    for (NSString *path in paths){
        filesName = [[path lastPathComponent] stringByDeletingPathExtension];
        filesPath = [parentDirectory stringByAppendingPathComponent:path];
        filesDirectory = [NSMutableDictionary dictionaryWithDictionary:[[NSFileManager defaultManager] attributesOfItemAtPath:filesPath error:nil]];        
        filesSize = [filesDirectory objectForKey:NSFileSize];
        filesType = [path pathExtension];
        createdDate = [filesDirectory objectForKey:NSFileCreationDate];
        modifiedDate = [filesDirectory objectForKey:NSFileModificationDate];
        filesDirectory = [NSDictionary dictionaryWithObjectsAndKeys:filesPath,@"filesPath",
                          filesName,@"filesName",filesSize, @"filesSize", filesType, @"filesType",
                          createdDate,@"createdDate", modifiedDate,@"modifiedDate", nil];
        NSLog(@"%@", filesDirectory);
    }
}

谢谢..

答案 2 :(得分:0)

您尚未保留directoryContent

您能否显示创建directoryContent的代码?

你可以告诉这个,因为你的错误信息是NSPathStore2,当它应该试图在NSDictionary上调用objectforKey时 - 这意味着你的字典所在的内存没有被其他东西使用:)