代码之家  ›  专栏  ›  技术社区  ›  iOS

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

  •  0
  • iOS  · 技术社区  · 15 年前

    我正在为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 回复  |  直到 15 年前
        1
  •  3
  •   Matthias Bauch    15 年前

    无论您在何处创建directoryContent,都会在其中存储错误的对象。
    NSPathStore2是一个对象,如果您使用 stringByAppendingPathComponent: 在NSString上。
    我猜您刚刚将文件名存储在数组中,但希望存储从NSFileManagers创建的NSDictionary attributesOfItemAtPath:error:

    检查该部分是否再次将对象添加到目录内容。

        2
  •  1
  •   iOS    15 年前

    这是我的密码。看看这个。让我知道我落后了什么。

    - (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);
        }
    }
    

    谢谢。。

        3
  •  0
  •   deanWombourne    15 年前

    你没有保留 directoryContent .

    你能告诉我密码在哪吗 目录内容 是创建的?

    您可以这样说,因为错误消息显示NSPathStore2应该在NSDictionary上尝试调用objectforKey-这意味着字典所在的内存没有被其他东西使用:)