我有一個地圖視圖控制器(UIViewController,MKMapView)及其委託(HCIResultMapViewController)。mkannotation中的自定義數據變量
我希望在這部分有以下功能。
1)。我希望用我的定製NSObject的,讓我能與像標題,副標題等基本實體沿着別人的信息關聯起來
因此,根據我的需要我編寫如下
在HCIResultMapViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_houseList = [[_resultList objectForKey:@"result"] objectForKey:@"listings"];
// NSLog([_houseList description]);
int i = 0;
for (NSDictionary *house in _houseList) {
HCIAnnotationViewController *annotation = [[HCIAnnotationViewController alloc]
initwithHouse:house];
[_mapView addAnnotation:annotation];
// NSLog(@"asdjhasdjsajdhaksdjghasdasdjahsdahskvdka");
self.currIdentifier = i;
i++;
}
[_mapView setShowsUserLocation:NO];
}
其他委託功能
-(void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
for (NSObject<MKAnnotation> *annotation in _mapView.selectedAnnotations) {
NSLog(@"hellomaster");
NSLog(annotation.title);
if ([annotation isKindOfClass:[HCIAnnotationViewController class]]) {
NSLog(@"hellomaster");
}
}
最後一個
-(MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
NSString *identifier = @"currIdentifier";
MKPinAnnotationView *annotationView =
(MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.tag = self.currIdentifier;
// Create a UIButton object to add on the
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[annotationView setRightCalloutAccessoryView:rightButton];
/*
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[annotationView setLeftCalloutAccessoryView:leftButton];
*/
return annotationView;
}
但我看到類等價失敗。你能告訴我我做錯了什麼嗎?
我想我想要的,簡單來說,我怎麼能發送一些數據(NSDictionary *)以及註釋,以便我可以隨時檢索它?
請不要標記爲重複的問題左右。我嘗試了很多問題,谷歌搜索等,但找不到合適的解決方案。
你想創建自定義註釋..例如標題,副標題? – iPatel 2013-03-11 12:24:38
沒有。我希望我的註釋包含一個NSDictionary *以及諸如標題,副標題之類的實體。 – 2013-03-11 12:26:38