2011-05-20 30 views
0

我是新的obj-c和iOS編程。 因此,在一個文件/模塊我已經寫了GPS +地圖,在這個文件/模塊我更新我的地理位置。 在另一個文件/模塊我有功能女巫採取地理定位形式的第一個文件/模塊作爲CLLocationCoordinate2D變種。小代碼部分巫婆解釋我的意思。 一些在GPS +地圖文件中的功能是:。如何將CLLocationCoordinate2D var發送到其他文件?

-(void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation { 
    if (AnotherModuleGeolocTaker!=nil) 
    [[AnotherModuleGeolocTaker getInstance] setLocation:[userLocation coordinate]]; 
... 

還有就是geoloc。二傳手。在另一個文件/ module.h中:

... 
@property (nonatomic, assign) CLLocationCoordinate2D location; 
... 

而在另一個文件/ module.m :.

... 
@synthesize location; 
... 
- (IBAction)ThereIsGeolocTakeAction:(id)sender { 
    NSLog(@"\n\nlatitude = %g\n\tlongitude = %g",location.latitude,location.longitude); 
... 

那麼如何發送座標形式 'didUpdateUserLocation' 到 'ThereIsGeolocTakeAction'?

回答

0

IBAction用於連接Interface Builder中的按鈕,因此當用戶點擊該按鈕時,會觸發方法調用。你不想在這裏。你只需要一個常規的方法。

在地圖文件中,內部didUpdateUserLocation:實現此代碼:

if (AnotherModuleGeolocTaker!=nil) { 
    [[AnotherModuleGeolocTaker getInstance] 
     ThereIsGeolocTakeAction:[userLocation coordinate]]; 
} 

在AnotherModuleGeolocTaker.m實現此方法:

-(void)ThereIsGeolocTakeAction:(CLLocationCoordinate2D)theNewLocation { 
    NSLog(@"\n\nlatitude = %g\n\tlongitude = %g", 
       theNewLocation.latitude,theNewLocation.longitude); 
    } 
相關問題