2010-06-11 95 views
1

我得到了我的應用程序工作回來,但完全和意外刪除它後,我試圖從一個方塊創建它。不幸的是我重寫的程序有點怪異;有沒有人看到或知道可能的錯誤來源?另外,我的if語句正在發揮作用。數組中的對象不被識別爲具有「方法」

-(void)loadAnnotations 
{ 
    CLLocationCoordinate2D workingCoordinate; 
    iProspectLiteAppDelegate *appDelegate = (iProspectLiteAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    NSMutableArray *mines =[[NSMutableArray alloc] initWithArray:(NSMutableArray *) appDelegate.mines]; 
    BOOL gold = [[NSUserDefaults standardUserDefaults] boolForKey:@"goldControl"]; 
    BOOL silver = [[NSUserDefaults standardUserDefaults] boolForKey:@"silverControl"]; 
    BOOL copper = [[NSUserDefaults standardUserDefaults] boolForKey:@"copperControl"]; 
    for(id mine in mines) 
    { 
    NSLog(@"in the loop"); 
    workingCoordinate.latitude = [[mine latitudeInitial] doubleValue]; 
    workingCoordinate.longitude = [[mine longitudeInitial] doubleValue]; 
    iProspectLiteAnnotation *tempMine = [[iProspectLiteAnnotation alloc] initWithCoordinate:workingCoordinate]; 
    [tempMine setTite:[mine mineName]]; 

    if ([[mine commodity] isEqualToString:@"Gold"] && [gold == YES]) 
    { 
     [tempMine setAnnotationType:iProspectLiteAnnotationTypeGold]; 
     [mapView addAnnotation:tempMine]; 
    } 
    if([[mine commodity] isEqualToString:@"Silver"] && [silver == YES]) 
    { 
     [tempMine setAnnotationType:iProspectLiteAnnotationTypeSilver]; 
    } 
    if([[mine commodity] isEqualToString:@"Copper"] && [copper == YES]) 
    { 
     [tempMine setAnnotationType:iProspectLiteAnnotationTypeCopper]; 
    } 
} 
[mines dealloc]; 
} 

其中workingCoordinate.latitude = [[礦latitudeInitial]的doubleValue],以及經度,和[礦mineName],它說: 「否 '-latitudeInitiallongitudeInitial' 方法找到」 或mineName/LongitudeInitial。 也,它抱怨:之前]在所有的if語句行。我沒有看到任何錯誤,是嗎?

+0

AGH !!!! **從不**自己調用'dealloc'!始終使用('auto')'release'! – 2010-06-11 05:56:05

+0

我該怎麼做? – 2010-06-11 06:13:38

+0

'[mines release];' – JeremyP 2010-06-11 07:53:13

回答

1

您正在使用一個迭代器,它爲您提供了類型爲id的對象 - 在這些對象上調用方法通常會混淆編譯器。你能將它們投射到一個已知的類型嗎?

for(MineType* mine in mines)

而且

[tempMine setTite:[mine mineName]]; 

那是一個錯字?我的猜測是你會打電話給那個方法setTitle

+0

好的setTite是一個錯字。我修復了很多。而你的解決方案工作! – 2010-06-11 04:36:38

0

我認爲在for循環中將mine對象的對象類型更改爲您擁有latitudeInitial,longitudeInitial,mineName屬性/方法的任何自定義類都應解決此問題。

+0

也是這樣做的。 – 2010-06-11 04:36:23