不要的問題知道什麼是錯這個陣列iphone:在NSMutableArray中和的NSMutableDictionary
NSMutableArray *locations=[[NSMutableArray alloc] init];
NSMutableDictionary *aLocation=[[NSMutableDictionary alloc] init];
[aLocation setObject:@"26.8465108" forKey:@"lat"];
[aLocation setObject:@"80.9466832" forKey:@"long"];
[locations addObject:aLocation];
[aLocation removeAllObjects]
[aLocation setObject:@"26.846127990018164" forKey:@"lat"];
[aLocation setObject:@"80.97541809082031" forKey:@"long"];
[locations addObject:aLocation];
[aLocation removeAllObjects];
但我每次刪除aLocations所有對象時辭典這些值也會從位置陣列刪除。
請幫我在這
如何這個東西然後 – 2011-05-12 12:57:56
你的答案是唯一正確的,讚美;-) PS:它也很容易創建一個可變的副本,然後再添加它[位置addObject:[[aLocation mutableCopy] autorelease]]]; – Jake 2011-05-12 13:15:59
在沒有'aLocation'變量的情況下編寫上面的代碼 - 即[[位置addObject:[NSDictionary dictionaryWithObjectsAndKeys:...]']可能會更加地道。就我個人而言,我也傾向於使用'latitude'和'longitude'屬性創建一個'Coordinate'類。 – alastair 2011-05-12 14:27:48