Ios 地图注释DidSelectAnnotationView w/Popover问题
这是我的问题 我有一个带有TableView和MapView的splitview控制器。相当标准的设置 在选择tableview时,我会向mapview发送一个通知,在注释中找到我要查找的对象的确切ID,然后选择它 下面是一段代码示例Ios 地图注释DidSelectAnnotationView w/Popover问题,ios,xcode,ios5,mapkit,uipopovercontroller,Ios,Xcode,Ios5,Mapkit,Uipopovercontroller,这是我的问题 我有一个带有TableView和MapView的splitview控制器。相当标准的设置 在选择tableview时,我会向mapview发送一个通知,在注释中找到我要查找的对象的确切ID,然后选择它 下面是一段代码示例 -(void)zoomToLocation:(NSNotification*)notification{ NSLog(@"zoomToLocation:"); NSNumber *storeID = [notification object];
-(void)zoomToLocation:(NSNotification*)notification{
NSLog(@"zoomToLocation:");
NSNumber *storeID = [notification object];
if (storeID ==nil || storeID.intValue == 0) {
return;
}
//Find the store out of Core Data Here
CLLocation *storeLocation = [[CLLocation alloc]initWithLatitude:zoomStore.latitude.doubleValue longitude:zoomStore.longitude.doubleValue];
MKCoordinateRegion mapRegion = MKCoordinateRegionMake(storeLocation.coordinate, MKCoordinateSpanMake(0.01, 0.01));
[self.cMapView setRegion:mapRegion animated: YES];
for (CustomAnnotationPin *annot in self.cMapView.annotations) {
if ([annot isKindOfClass:[RBMapAnnotationPin class]]) {
if(zoomStore.storeID.intValue == annot.storeID.intValue){
[self.cMapView selectAnnotation:annot animated:YES];
}
}
}
}
这是100%正确的。我可以随意“缩放”到注释性图钉。真正的问题是,我希望在选择注释时以编程方式显示弹出框
我正在使用委托函数didSelectAnnotationView
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if ([view.annotation isKindOfClass:[MKUserLocation class]]) {
return;
}
NSLog(@"DidSelect");
[self.cMapView deselectAnnotation:view.annotation animated:NO];
selectedPin = view.annotation;
if(!mapPop){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
MapCalloutViewController *mapCallout = [storyboard instantiateViewControllerWithIdentifier:@"mapCalloutVC"];
//Find the store in Core Data with the proper ID from the selected pin ID and give it to the VC for data
mapPop = [[UIPopoverController alloc]initWithContentViewController:mapCallout];
[mapPop setDelegate:self];
[mapPop setPopoverContentSize:CGSizeMake(370, 230)];
[mapPop presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
if ([self.delegate respondsToSelector:@selector(mapStoreSelectionChanged:)]) {
[self.delegate mapStoreSelectionChanged:mapCallout.store];
}
}
}
因此,这里有一个问题。该代码在模拟器中工作得非常好。我缩放到该位置,调用mapDelegate并弹出注释
在设备上,代码的工作方式不同。在设备上,我必须双击商店才能显示地图弹出框(我不知道为什么,所以这相当令人沮丧)