嘗試將對象添加到可變數組時,似乎有一個奇怪的問題。事情是我有一個字典數組,我從外部數據庫獲得座標,我嘗試通過它們循環,提取座標,創建一個自定義註釋對象,然後將其添加到可變數組中。可可:將對象從循環添加到可變數組時出錯
的問題是數組我讓他們在表明,只有1個對象和第一陣列5
請幫幫忙!
下面是代碼(注:testArray是我的類的屬性我不創建它吼叫,我只是嘗試用它來存儲對象)
謝謝!
int times; int count;
count=[theResults count];
// do the loop oh yeah do the loop
for (times=0;times<count; times=times+1)
{
// create dictionary with contents of array
NSDictionary * testDict = [theResults objectAtIndex:times];
NSLog(@"the results has %i objects", [theResults count]);
NSLog(@"object latitude is %@",[radarDict valueForKey:@"radarLatitude"]);
NSLog(@"object longitude is %@", [radarDict valueForKey:@"radarLongitude"]);
double testLatitude=[[radarDict valueForKey:@"radarLatitude"] doubleValue];
double testLongitude=[[radarDict valueForKey:@"radarLongitude"] doubleValue];
CLLocationCoordinate2D testCoordinate;
testCoordinate.longitude=testLongitude;
testCoordinate.latitude=testLatitude;
CustomAnnotations* tempAnnotation = [[CustomAnnotations alloc] initWithLocation:testCoordinate];
testArray = [[NSMutableArray alloc] initWithCapacity:count];
[testArray addObject:tempAnnotation];
[tempAnnotation release];
}
非常感謝!我剛剛看到了。其顯而易見,但它不是我:)謝謝 – Daniel
不用擔心,我們都做這樣的事情:) – sosborn