2012-01-16 10 views
0

新しいXcode 4.2にアップグレードしたばかりで、plistのマップ注釈の読み込みに問題があります。私は定期的に更新するURLにplistを持っている必要があります。Xcode 4.2マップビューinitWithDictionary

私はXcodeの古いバージョンで問題はなかったが、今ARCのエラーを取得し、

Receiver type 'MapAnnotations' for instance message does not declare a method with selector 'initWithDictionary'.

ていますすべてのヘルプは大歓迎です。前もって感謝します。 Mapview.M

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Locations" ofType:@"plist"]; 
NSArray *array = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.MyPlist.plist"]]; 

if (array) { 
    NSDictionary* myDict = [NSMutableDictionary dictionaryWithCapacity:[array count]]; 
    for (NSDictionary* dict in array) { 
     MapAnnotations* annotation = [[MapAnnotations alloc]iniWithDictionary:dict]; 
     [mapview addAnnotation:annotation]; 
    } 
    NSLog(@"The count: %i", [myDict count]); 
} 

else { 
    NSLog(@"Plist does not exist"); 
} 

答えて

2

MapAnnotations.mコード

-(id)initWithDictionary:(NSDictionary *)dict { 
self = [super init]; 
if (self!=nil) { 
    coordinate.latitude = [[dict objectForKey:@"latitude"] doubleValue]; 
    coordinate.longitude = [[dict objectForKey:@"longitude"] doubleValue]; 
    self.title = [dict objectForKey:@"name"]; 
    self.subtitle = [dict objectForKey:@"subtitle"]; 
    self.pin = [dict objectForKey:@"pin"]; 
} 
return self; 

}

セクションこのエラー:

Receiver type 'MapAnnotations' for instance message does not declare a method with selector 'initWithDictionary'

initWithDictionary方法がなかったことを意味MapAnnotations.hで宣言されています。古いXcodeでは、これは警告に過ぎないと思います。

MapAnnotations* annotation = [[MapAnnotations alloc]iniWithDictionary:dict]; 

それはinitWithDictionaryを言う必要があります(ないiniWithDictionary:私は、この行がちょうどあなたの質問のタイプミスであると仮定し、ところで

@interface MapAnnotations : NSObject<MKAnnotation> 

//any ivars, properties, and other method declarations here 

-(id)initWithDictionary:(NSDictionary *)dict; // <-- add this 

@end 


MapAnnotations.h

は、メソッドを宣言します)。

+0

ありがとうございます。それが私の問題でした。私はまだこのコードのすべてを頭の中に入れています。私はそれほど感謝しています! – Craig