我無法將字典添加到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
不過,下一次有問題時,請提供更多信息。人們顯然能夠猜出你的問題,但在你發佈的內容中找不到。 –