Xcode 4.2地图视图initWithDictionary

问题描述:

我刚刚升级到新的Xcode 4.2,并且遇到了从我的plist加载地图注释的问题。我需要定期更新网址上的plist。Xcode 4.2地图视图initWithDictionary

我曾与旧版本的Xcode没有问题,但我现在得到一个ARC错误和

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

任何帮助是极大的赞赏。先谢谢你。

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; 

}在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"); 
} 

此错误:

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

意味着initWithDictionary方法尚未在MapAnnotations.h中声明。在旧的Xcode中,我认为这只会导致警告。

MapAnnotations.h,申报方法:

@interface MapAnnotations : NSObject<MKAnnotation> 

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

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

@end 


顺便说一句,我认为此行只是在你的问题一个错字:

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

应该说initWithDictionary(不iniWithDictionary )。

+0

非常感谢。那是我的问题。我仍然围绕着所有这些代码。我很欣赏它mucho! – Craig 2012-01-17 20:38:03