- [NSPathStore2 objectForKey:]: нераспознанный селектор отправлен на экземпляр 0x6a3fc60 ' - PullRequest
0 голосов
/ 15 ноября 2010

Я готовился к customCellView в tableView. По-моему, все было идеально в .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 ]

3 голосов
/ 15 ноября 2010

Где бы вы ни создавали directoryContent, вы сохраняли в нем неправильный объект.
NSPathStore2 - это объект, который будет создан, если вы используете что-то вроде stringByAppendingPathComponent: в строке NSString.
Полагаю, вы просто сохранили имя файла вмассив, но хотел сохранить NSDictionary, созданный из NSFileManagers attributesOfItemAtPath:error:

Проверьте, что часть, вы снова добавили объекты в directoryContent.

1 голос
/ 16 ноября 2010

Это мой код.Посмотри на это!Дайте мне знать, что я отстаю.

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

Спасибо ..

0 голосов
/ 15 ноября 2010

Вы не сохранили directoryContent.

Можете ли вы показать код, где создается directoryContent?

Вы можете сказать это, потому что ваше сообщение об ошибке говорит NSPathStore2, когда он должен пытаться вызвать objectforKey для NSDictionary - это означает, что память, в которой находился ваш словарь, не используется чем-то другим:)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...