2010-11-15 30 views
0

我正準備在tableView中使用customCellView。據我所知,在.xib和方法中一切都很完美。我在配置單元時遇到了異常。- [NSPathStore2 objectForKey:]:無法識別的選擇器發送到實例0x6a3fc60'

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' 

請幫我繼續..謝謝你提前終止..

+0

在我看來,對於按鍵的對象之一是缺少,但不能肯定。也許你可以試着改變listIndex是如何由常量定義的,你肯定應該能夠工作。 – Vanya 2010-11-15 16:43:18

+0

顯示所有與'directoryContent'的值有關的代碼。 – 2010-11-15 22:03:00

+0

嗨。我在下一個答案中發佈了我的代碼。看看那個。 – iOS 2010-11-16 06:41:54

回答

3

你的字典無論您創建的記憶directoryContent,你在其中存儲了錯誤的對象。
NSPathStore2是一個將在NSString上使用類似stringByAppendingPathComponent:的對象。
我猜你只是存儲在陣列中的文件名,但希望存儲的NSDictionary從NSFileManagers attributesOfItemAtPath:error:

檢查部分是添加對象再次directoryContent創建。

+0

嗨。我在下一個答案中發佈了我的代碼。看看那個。 – iOS 2010-11-16 06:42:42

+0

謝謝。它的工作.. – iOS 2010-11-18 12:27:10

0

您沒有保留directoryContent

您能顯示代碼directoryContent的地方嗎?

可以這麼說,是因爲你的錯誤消息指出NSPathStore2時,應該試圖調用objectforKey上的NSDictionary - 這意味着,如果在不使用別的東西:)

+0

如果這將是這種情況的例外將是' - [NSPathStore2 objectAtIndex:]:無法識別的選擇器發送到實例' – 2010-11-15 19:27:07

+0

嗨。我在下一個答案中發佈了我的代碼。看看那個。 – iOS 2010-11-16 06:42:21

+0

@fluchtpunkt - 雖然我已經看到了目錄內容的內存足夠好的情況下指向另一個無效的內存位置,其中引發異常幾乎100%正確 - 我們泄漏了數組的內容,而不是數組本身。 – deanWombourne 2010-11-16 17:49:19

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

謝謝..

+0

沒有任何代碼將文件目錄添加到directoryContent數組。 。 。 – deanWombourne 2010-11-16 17:51:07

相關問題