我有一个地图视图控制器(UIViewController,MKMapView)及其委托(HCIResultMapViewController).
我希望在这部分中具有以下功能.
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];
}
Run Code Online (Sandbox Code Playgroud)
其他代表职能
-(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");
}
}
Run Code Online (Sandbox Code Playgroud)
最后一个
-(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;
}
Run Code Online (Sandbox Code Playgroud)
但我发现类等价失败了.你能告诉我我做错了什么吗?
我想我想要的是,简单来说,我怎样才能发送一些数据(NSDictionary*)和注释,以便我可以随时检索它?
请不要将此标记为重复的问题.我尝试了很多问题,谷歌搜索等,但找不到合适的解决方案.
我找不到实现自定义数据变量的确切方法或我的类等效性失败的原因。但我想出了一个办法来克服这种情况。这在方法上可能是多余的,但仍然很有魅力。
所以我们的想法是在控制按钮中使用标签系统。我观察到,每次我向地图视图发送消息以添加注释时,它都会立即调用我的 viewforannotation 方法。由于我正在遍历数组,因此我维护了一个索引全局指针,用它来设置控制按钮的标签。稍后,当单击该按钮时,我检索标签并使用它来获取我想要的对象。
其他人有任何替代或直接的解决方案,请发布。
| 归档时间: |
|
| 查看次数: |
465 次 |
| 最近记录: |