最新の SDK を使用して iOS アプリを開発しています。
次のメソッドにセレクターがあり、別の引数を渡す必要があります。
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
NSLog(@"viewForAnnotation");
MKAnnotationView *annotationView = nil;
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[ShopAnnotation class]])
{
// try to dequeue an existing pin view first
static NSString *ReusableAnnotationIdentifier = @"reusableShopAnnotationIdentifier";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:ReusableAnnotationIdentifier];
if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:ReusableAnnotationIdentifier];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
// add a detail disclosure button to the callout which will open a new view controller page
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
annotationView = pinView;
}
return annotationView;
}
オブジェクトをに渡す必要がありますshowDetails:
:
// add a detail disclosure button to the callout which will open a new view controller page
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
showDetails
実装方法は次のとおりです。
- (void) showDetails:(id)sender
{
NSLog(@"Show Details");
DetailViewController* mvc = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPhone" bundle:nil];
mvc.delegate = self;
[self presentModalViewController:mvc animated:YES];
}
これはShopAnnotation
インターフェースです:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import <CoreData/CoreData.h>
@interface ShopAnnotation : NSObject <MKAnnotation>
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly, strong) NSString *title;
@property (nonatomic, readonly, strong) NSString *subtitle;
@property (nonatomic, readonly, strong) NSManagedObject* shop;
-(id)initWithCoordinate:(CLLocationCoordinate2D) c
title:(NSString *) t
subtitle:(NSString *) st
shop:(NSManagedObject*) shop;
@end
どうすれば別の引数を追加できshowDetails
、どのように渡すことができますか?
showDetails
になります:
- (void) showDetails:(id)sender shop:(NSManagedObject*)shop
で、これは何(id)sender
?これは、これを渡すために使用できる注釈ですNSManagedObject
。