我无法将字典添加到nsmutabledictionary。任何人都可以看到我做错了什么?将条目添加到NSMutableDictionary
@interface viewMap : UIViewController<MKMapViewDelegate> {
NSMutableDictionary *onclickDic;
}
@property (nonatomic, retain) NSMutableDictionary *onclickDic;
@end
@implementation viewMap
@synthesize onclickDic;
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSString *pushLat = [NSString stringWithFormat:@"%f", [annotation coordinate].latitude];
NSString *pushLng = [NSString stringWithFormat:@"%f", [annotation coordinate].longitude];
NSDictionary *latlngDic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:pushLat, pushLng, nil] forKeys:[NSArray arrayWithObjects:@"lat", @"lng", nil]];
NSDictionary *toPush = [NSDictionary dictionaryWithObject:latlngDic forKey:[NSString stringWithFormat:@"%i", i]];
NSLog(@"toPush is %@", toPush); // this one is correct and works
[self.onclickDic addEntriesFromDictionary:toPush];
NSLog(@"onclickDic is %@", onclickDic); // this one gives (null)
}
@end
“遇到的麻烦”没有一些更多的信息是一个问题。究竟出了什么问题?如果有错误信息,它是什么,错误发生在哪里? –
@Rudy Velthuis谢谢你的回答。下面的答案帮了我。我忘了alloc/init并释放对象clickDic – Melvin
不过,下一次有问题时,请提供更多信息。人们显然能够猜出你的问题,但在你发布的内容中找不到。 –