我对Objective C编程很新。我有这个问题,我找不到解决方案,尽管有很多关于此的主题。
我得到了这些注释,这一切都完美无缺,直到我点击按钮并进入下一个视图..如何获取注释的标题,发送到我的新视图控制器,国家/地区?
·H:
@interface SCSecondViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;
}
@property(nonatomic, retain) IBOutlet MKMapView *mapView;
@end
的.m:
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
[mapView setDelegate:self];
MKCoordinateRegion bigBen = { {0.0, 0.0} , {0.0, 0.0} };
bigBen.center.latitude = 51.50063;
bigBen.center.longitude = -0.124629;
bigBen.span.longitudeDelta = 0.02f;
bigBen.span.latitudeDelta = 0.02f;
[mapView setRegion:bigBen animated:YES];
Annotation *ann1 = [[Annotation alloc] init];
ann1.title = @"England";
ann1.subtitle = @"Num_rows";
ann1.coordinate = bigBen.center;
[mapView addAnnotation:ann1];
MKCoordinateRegion Bridge = { {0.0, 0.0} , {0.0, 0.0} };
Bridge.center.latitude = 51.500809;
Bridge.center.longitude = -0.120914;
Bridge.span.longitudeDelta = 0.02f;
Bridge.span.latitudeDelta = 0.02f;
[mapView setRegion:Bridge animated:YES];
Annotation *ann2 = [[Annotation alloc] init];
ann2.title = @"Bridge";
ann2.subtitle = @"Bridge";
ann2.coordinate = Bridge.center;
[mapView addAnnotation:ann2];
// Do any additional setup after loading the view, typically from a nib.
}
-(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 {
UIViewController* Countries = [[UIViewController alloc] initWithNibName:@"Countries" bundle:[NSBundle mainBundle]];
[self.view addSubview:Countries.view];
}
annotation.h:
@interface Annotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
annotation.m:
@implementation Annotation
@synthesize coordinate, title, subtitle;
@end
欣赏各种帮助!我真的被困在这里......