我是obj-c和iOS编程的新手。所以在一个文件/模块中,我写了GPS+地图,在这个文件/模块中我更新了我的地理位置。在另一个文件/模块中,我让函数女巫从第一个文件/模块中获取地理位置作为 CLLocationCoordinate2D var。有小代码部分女巫解释我的意思。GPS+地图文件中的某些软件是函数:。
-(void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation {
if (AnotherModuleGeolocTaker!=nil)
[[AnotherModuleGeolocTaker getInstance] setLocation:[userLocation coordinate]];
...
有地理定位器。在另一个文件/模块中。
...
@property (nonatomic, assign) CLLocationCoordinate2D location;
...
并在另一个文件/模块中:。
...
@synthesize location;
...
- (IBAction)ThereIsGeolocTakeAction:(id)sender {
NSLog(@"nnlatitude = %gntlongitude = %g",location.latitude,location.longitude);
...
那么如何将坐标从"didUpdateUserLocation"发送到"ThereIsGeolocTakeAction"?
IBAction 用于连接界面生成器中的按钮,因此当用户点击该按钮时,它会触发方法调用。 你不希望在这里。 你只需要一个常规的方法。
在映射文件中,在didUpdateUserLocation中:实现以下代码:
if (AnotherModuleGeolocTaker!=nil) {
[[AnotherModuleGeolocTaker getInstance]
ThereIsGeolocTakeAction:[userLocation coordinate]];
}
在 OtherModuleGeolocTaker.m 中实现此方法:
-(void)ThereIsGeolocTakeAction:(CLLocationCoordinate2D)theNewLocation {
NSLog(@"nnlatitude = %gntlongitude = %g",
theNewLocation.latitude,theNewLocation.longitude);
}