2010-03-19 110 views
0

在程序的一部分的兩個陣列內我的工作,我需要計算所有的時候,每個人有每個人的其他項目的工作。假設我們有「員工」實體和「會話」實體。在每個會話中,有四個項目類型,分別是「A」,「B」,「C」,&「D」,每個項目類型都與員工建立多對多關係。檢索關係從指針

我正在做一個循環來系統地審查每個人所選擇的人合作過。首先,我將他們所有的項目類型放在一個數組中,所以它更容易循環,但是當我問最後一個嵌套的Project作爲它的Employee成員時,我得到一個「無法識別的選擇器」的錯誤。

IBOutlet NSArrayController * superList; 

編輯:我忘了表示這個數組,指向控制器的arrangeObjects。

NSArray * list = [superList arrangedObjects]; 
int x; 
for(x = 0; x < [list count]; x++){ 
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectAs"]; 
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectBs"]; 
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectCs"]; 
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectDs"]; 

NSArray *masterList = [[NSArray alloc] initWithObjects: projectAs, projectBs, projectCs, projectDs, nil]; 

int y; 
for(y = 0; y < [masterList count]; y++){ 
int z; 
for(z = 0; z < [[masterlist objectAtIndex:y] count]; z++){ 
//And now to make an Array of this employee's partners on the selected object, to run comparisons on. 
//I also have an array of keys for each session's teams, so that's what I'm referencing here: 
NSArray * thisTeam = [list objectAtIndex:y] objectAtIndex:z] valueForKey:projectKey]; 

這將引發異常......即 - [_ NSFaultingMutableSet objectAtIndex:]:無法識別的選擇發送到實例

出了什麼問題,去年數組創建?

+0

我看不出有什麼理由要在這裏使用'objectAtIndex:'而不是快速枚舉:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocFastEnumeration。 html#// apple_ref/doc/uid/TP30001163-CH18-SW1它不會解決您的問題(並且您應該只在此之後進行更改),但它會使代碼更易於閱讀。 – 2010-03-19 23:41:07

+0

這是我在Python中知道的一個重要特性,但沒有在Kochan的Obj-C書中讀過。非常感謝分享! – DanF 2010-03-21 04:00:03

回答

1

基於您的線路:

的NSArray * A = [[列表objectAtIndex:X] valueForKey:@ 「projectAs」];

召喚:

[名單objectAtIndex:Y]

不返回數組 - 它返回的NSDictionary,這意味着你不能調用objectAtIndex:z有關結果。

看來這應該是[masterlist objectAtIndex:Y]?

+0

你死了,但我只是意識到我誤解了我的代碼。 「list」應該是一個指向AC的排列對象的數組,而不是AC本身。看到問題了嗎? – DanF 2010-03-19 18:32:21

+0

試試這個: id whatAmI = [list objectAtIndex:y]; 的NSLog(@ 「%@」,whatAmI」); 的NSArray * thisTeam = [[whatAmI objectAtIndex:Z] valueForKey:projectKey]; 在這一點上,我們需要知道到底是什麼[名單objectAtIndex:Y] – ericg 2010-03-19 18:51:24

+0

所以我認爲問題是,我不確定什麼樣的對象是當我查詢一個員工(或「玩家」)檢索什麼他們的valueForKey:@「redTeams」是。我希望有一個數組或設置到許多情況下,這應該記得的,但是當我做了ID-NSLog的測試中,它調用鍵的結果: 關係的對象爲{( (單位:展會; ID:0x100e75500 ; data: 這似乎是一個單一的對象,而不是一個集合或數組。 – DanF 2010-03-20 06:39:17