#import "MainViewController.h"
#import "MyFirstAnnotation.h"
@implementation MainViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)annosetzen:(id)sender{
CLLocationCoordinate2D coor;
coor.latitude = 54.3327162876622;
coor.longitude = 10.1518177986145;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
MKCoordinateRegion region;
region.center = coor;
region.span = span;
MyFirstAnnotation *anno = [[MyFirstAnnotation alloc]init];
[mapView addAnnotation:anno];
[mapView setRegion:region animated:TRUE];
//MKReverseGeocoder *revGeo = [[MKReverseGeocoder alloc] initWithCoordinate:coor];
//revGeo.delegate = self;
//[revGeo start];
}
接下来.m必须得到字符串
#import "MyFirstAnnotation.h"
@implementation MyFirstAnnotation
- (CLLocationCoordinate2D)coordinate {
CLLocationCoordinate2D coor;
coor.latitude = 54.3327162876622;
coor.longitude = 10.1518177986145;
return coor;
}
- (NSString *)title {
return theTitle;
}
- (NSString *)subtitle {
return theSubTitle;
}
Title和theSubTitle是字符串,必须从MainViewController .m传递才能在MyFirstAnnotation中使用.m
你有一个简单的例子怎么做?我真的很想找到这个简单的步骤,但我找到了答案: - (
请帮帮我
答案 0 :(得分:0)
您可能想要这样做?
MyFirstAnnotation *anno = [[MyFirstAnnotation alloc] init];
NSString *one = [anno title];
NSString *two = [anno subtitle];
编辑:要设置字符串从第一个文件到第二个,你应该将setter方法添加到
MyFirstAnnotation.h
//...
- (void)setTitle:(NSString*)title;
//...
- (void)setSubTitle:(NSString*)subTitle {
MyFirstAnnotation.m
//...
- (void)setTitle:(NSString*)title {
theTitle = [title copy];
}
//...
- (void)setSubTitle:(NSString*)subTitle {
theSubTitle = [subTitle copy];
}
然后从主文件中调用它们:
// ....
MyFirstAnnotation *anno = [[MyFirstAnnotation alloc]init];
[anno setTitle:@"qwertt"];
[anno setSubTitle:@"asdfg"];
// ....