2012-01-31 21 views
0

3つのオブジェクト、2つのNSTextField、1つのNSImageViewを持つNSCollectionViewがあります。ユーザーがフォルダを選択してそのフォルダの内容を読み取るようにして、データを取得しています。ファイル名、パス、スニフをタイプ(ファイル/フォルダ)にプルし、フォルダであればアイコン(NSWorkspaceを使用)を取得するか、ファイルであるかどうかを確認します。 (これらはすべてイメージファイルでなければなりません。チェックする場所にフィルタがあります)。NSCollectionエラー:NSImageオブジェクトからNSDataを作成できません

とにかく、私のバインディングは、テキストフィールドにデータが取り込まれるように見えますが、NSImageViewはそうではなく、私のモデルにNSImageを渡そうとするとこのエラーメッセージが表示されます。

//loop through the data 
for (NSString* thisItemKey in fileManagerResults) { 

    //get our item data dictionary 
    NSDictionary* thisItemData = [fileManagerResults objectForKey:thisItemKey]; 
    //get the item name 
    NSString* itemName = [thisItemData objectForKey:@"Item Name"]; 

    //filter for hidden files 
    NSString *value = [itemName substringWithRange:NSMakeRange(0, 1)]; 
    if(![value isEqualToString:@"."]) { 

     //make a new imageModel 
     ImageModel* thisImageModel = [[ImageModel alloc] init]; 

     //add some data to our image model 
     thisImageModel.itemName = itemName; 
     thisImageModel.itemType = [thisItemData objectForKey:@"Item Type"]; 
     thisImageModel.itemPath = [thisItemData objectForKey:@"Item Path"]; 
     thisImageModel.creationDate = [thisItemData objectForKey:@"Creation Date"]; 

     //get the file icon 
     NSImage* theItemIcon; 
     NSString* itemType = [thisItemData objectForKey:@"Item Type"]; 
     if ([itemType isEqualToString:@"Directory"]) { 
      theItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[thisItemData objectForKey:@"Item Path"]]; 

     } else { 
      theItemIcon = [[NSImage alloc] initWithContentsOfFile:[thisItemData objectForKey:@"Item Path"]]; 
     } 

     thisImageModel.itemIcon = theItemIcon; 

     [tempArray addObject:thisImageModel]; 



    } 

    //pass the data to our controller 
    [self setControllerArray:tempArray]; 


} 

私はこのかかわらずを実行するたびに、私は次のようなエラーメッセージが表示されます:解決

Cannot create NSData from object NSImage 0x16074e10 Size={450, 350} Reps=(
NSBitmapImageRep 0x16075ba0 Size={450, 350} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=24 Pixels=450x350 Alpha=NO Planar=NO Format=0 
) of class NSImage 

誰かがこれを修正するために、正しい方向に私を指すことができます...おかげ

答えて

0

、私が選択しました私の拘束のためのデータであり、IBの値ではありません。はい、私は大きな恥をもってここに座っています。 :D

+2

このような恥のない人は、実際のコードを書いていません。 – Rayfleck

+0

それから、私は毎日実際のコードを書いています...:D – PruitIgoe

関連する問題