如何从我的数组中获取电话对象到我的地图注释调用上的按钮?
我从 JSON 数组中加载引脚就好了,我正在从电话号码中解析出地址。按下呼叫时,如何在按钮上获取正确的电话号码?
for(id key in json) {
id value = [json objectForKey:key];
NSString *titlePin = [value valueForKey:@"address"];
NSString *addressPhone = [value valueForKey:@"title"];
NSString *latitude = [value valueForKey:@"latitude"];
NSString *longitude = [value valueForKey:@"longitude"];
NSArray* foo = [addressPhone componentsSeparatedByString: @":"];
NSString* justAddress = [foo objectAtIndex: 0];
NSString* phone = [foo objectAtIndex: 1];
double myLatitude = [latitude doubleValue];
double myLongitude = [longitude doubleValue];
MKCoordinateRegion location1;
location1.center.latitude =myLatitude;
location1.center.longitude= myLongitude;
location1.span.longitudeDelta=0.1;
location1.span.latitudeDelta =0.1;
MapAnnotation *ann1 =[[[MapAnnotation alloc] init] autorelease];
ann1.title=[NSString stringWithFormat:@"%@",titlePin];
ann1.subtitle=[NSString stringWithFormat:@"%@",justAddress];
//EDIT added this line for part of sollution
ann1.phone=[NSString stringWithFormat:@"%@",phone];
ann1.coordinate= location1.center;
[mapView addAnnotation:ann1];
}
}
}
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
MyPin.pinColor = MKPinAnnotationColorPurple;
UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = advertButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=TRUE;
MyPin.canShowCallout = YES;
return MyPin;
}
-(void)button:(id)sender {
// Call the phone number here!!!!!!!
//NSLog(@"Button action: %@",phone);
}
地图注释.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface MapAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *phone;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *phone;
@end
地图注释.m
#import "MapAnnotation.h"
@implementation MapAnnotation
@synthesize coordinate, title, subtitle, phone;
-(void)dealloc
{
[title release];
[subtitle release];
[phone release];
[super release];
[super dealloc];
}
@end