コールアウトを使用して MKMapView に注釈があります。この吹き出しには、「右矢印」ボタンがあります。それをクリックすると、詳細ビュー、独自の nib ファイルを含む追加の UIViewController などを開きたいと思います。次のコードを使用します。
私のMapViewControllerで:
- (void)showDetails:(id)sender {
// the detail view does not want a toolbar so hide it
[self.navigationController setToolbarHidden:YES animated:NO];
NSLog(@"pressed!");
[self.navigationController pushViewController:self.detailViewController animated:YES];
NSLog(@"pressed --- 2!");
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation *) annotation {
if(annotation == map.userLocation) return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorRed;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
UIImageView *memorialIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"googlemaps_pin.png"]];
customPinView.leftCalloutAccessoryView = memorialIcon;
[memorialIcon release];
return customPinView;
}
showDetais メソッド内で NSLog を指定すると、コンソールに出力されるため、ボタンが機能します。問題は、何も起こらないことです。ボタンをクリックすると、ボタンがないように見えます。デバッグ エラーや例外はなく、何もありません。
MapView ヘッダーは次のようになります。
@interface MapViewController : UIViewController <MKMapViewDelegate> {
MKMapView *map;
NSMutableDictionary *dictionary;
EntryDetailController *detailViewController;
}
@property (nonatomic,retain) IBOutlet MKMapView *map;
@property (nonatomic,retain) IBOutlet EntryDetailController *detailViewController;
多分あなたの誰かが私を助けることができます:)
ありがとう!