2013-02-04 30 views
-1

---- ---- EDITED字典綁定數組NSTableView的

我的情況:我有一個細胞爲基礎的NSTableView。在這個tableview中有3 NSColums,1是一個圖像框,一個是文本框,第三個是複選框。 我有一個陣列控制器,即beeing填入下面的代碼:

[imgArrayController addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSImage imageNamed:[NSString stringWithFormat:@"%@" ,fileName]], @"image", [NSString stringWithFormat:@"%@" ,fileName], @"filename", [NSNumber numberWithBool: YES], @"check1", nil]]; 

但此代碼不能正常工作。我從各種測試中知道這個代碼不工作,它添加了行,但它們是空的。其4天我正在尋找這個解決方案,現在沒有任何運氣。

感謝

+0

好友請發問短期和精細的方式,從而使他人找到感興趣的爲您解答。我試圖回答你,但你的問題對我來說還不清楚。 – Lalit

+0

感謝您花時間回答。好吧,我的問題是我需要在運行時將行添加到表中。我用我貼的長碼做。在NSTableview中顯示行,但它們是空白的,不顯示任何內容。我認爲這個錯誤在我發佈的代碼中是有的,因爲綁定到表格是我過去已經做過的事情。其3天我試圖解決這個問題沒有成功..謝謝! – sharkyenergy

+0

嘗試添加'[imgArrayController rearrangeObjects]'和'[tableView reloadData]'。如果這不會幫助檢查綁定。 – VenoMKO

回答

0

不知道你的圖像部分是正確的..試試這個:

NSMutableDictionary *imgdtl = [[NSMutableDictionary alloc] init]; 

    NSImage *myimage = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@" ,fileName]];   
    [imgdtl setObject: myimage forKey: @"image"]; 
    [imgdtl setObject:[NSString stringWithFormat:@"%@" ,fileName] forKey: @"filename"]; 
    [imgdtl setObject:[NSNumber numberWithBool: YES] forKey: @"check1"]; 
    [imgArrayController addObject:[imgdtl copy]];