これが私の問題です
TableView と MapView を持つ splitview コントローラーがあります。かなり標準的なセットアップ。
テーブルビューの選択時に、マップビューに通知を送信して、探しているオブジェクトの正確な ID を、持っている注釈内で見つけて選択します。
コードのサンプル スニップを次に示します。
-(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 が呼び出されて注釈がポップされます。
デバイスでは、コードは同じようには機能しません。デバイスでマップ ポップオーバーを表示するには、Store をダブルタップする必要があります (理由がわからないので、かなりイライラします)。