배열에서 내지도 주석의 버튼으로 전화 객체를 호출하려면 어떻게해야합니까?JSON 맵 주석의 문자열을 iOS의 버튼 호출에 전달하는 방법은 무엇입니까?
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);
}
MapAnnotaion.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
MapAnnotaion.m
#import "MapAnnotation.h"
@implementation MapAnnotation
@synthesize coordinate, title, subtitle, phone;
-(void)dealloc
{
[title release];
[subtitle release];
[phone release];
[super release];
[super dealloc];
}
@end
하위 클래스에 보여줍니다 알림 –