2011-03-27 115 views
0
#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从一个.M将字符串传递到另一个.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; 
} 

标题和theSubTitle是字符串,并且必须从MainViewController .M传递给在MyFirstAnnotation中使用.m

你有一个简单的例子如何做到这一点?林真的长寻找这个简单的步骤,但我dosnt找到答案:-(

请帮我

+0

你可以从你的实现添加到父类或委托,然后引用呢? – 2011-03-27 19:23:28

+0

可能的重复[如何将字符串从一个.m传递到另一个.m文件](http://stackoverflow.com/questions/5451172/how-to-pass-a-string-from-one-m-to -another-m文件)。如有必要,请编辑您的问题,而不是多次张贴基本相同的东西。 – Caleb 2011-03-27 19:34:43

回答

0

你可能想这样做

MyFirstAnnotation *anno = [[MyFirstAnnotation alloc] init]; 
NSString *one = [anno title];  
NSString *two = [anno subtitle]; 

编辑:设置从第一个文件的字符串第二,你应该补充制定者的方法来

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"]; 
// .... 
相关问题