2011-03-27 114 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"]; 
// .... 
相關問題