我有NSObjects(mapArray)的陣列,並且對象被聚焦在位置0(MAIN_MAP)。在每個NSObject中,都有一個名爲moonGateArray的NSMutableArray(擁有@property和@synthesize),我添加了另一個名爲Moongate的NSObject。但是,我一直得到零作爲moonGateArray的計數。任何答案爲什麼是這樣?計數是在對象的NSMutable數組返回0
代碼:
for (int i = 0; i < 8; i++) {
[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] addObject:[Moongate new]];
}
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:0] setPosition:9 :3];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:1] setPosition:16 :8];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:2] setPosition:11 :6];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:3] setPosition:16 :13];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:4] setPosition:13 :10];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:5] setPosition:3 :1];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:6] setPosition:3 :12];
[[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] objectAtIndex:7] setPosition:22 :17];
NSLog(@"%i",[[[mapArray objectAtIndex:MAIN_MAP] moonGateArray] count]);
你是否初始化了moonGateArray和mapArray? –