开发者

Accessing a variable which belong to another function in Xcode

开发者 https://www.devze.com 2023-01-25 21:33 出处:网络
Please take it easy on me.I\'m a newbie and is trying to learn mapkit.Just wondering if you can help me find my way with this one.. I have a function which find the coordinate in AppViewController.m

Please take it easy on me. I'm a newbie and is trying to learn mapkit. Just wondering if you can help me find my way with this one.. I have a function which find the coordinate in AppViewController.m

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLoc开发者_运维技巧ation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    CLLocationCoordinate2D location = [newLocation coordinate]; NSString *lat = [[NSString alloc] initWithFormat:@"%f", loc.latitude]; latitude.text = lat; ...

}

My question is, is there a way I can access the variable lat, say something like declaring it as a global varaible, from function - (void) viewDidLoad { ... }

This might sound a stupid question for most of you, but please give me a hint.. I've been reading about singleton.. but couldn't understand how I can use implement this in this one.

Kind Regards, David


You have to make lat an instance variable. Declare it in your class's @interface section, then you can access it from any method inside the class.

@interface AppViewController : UIViewController
{
    NSString *lat;
}

...

@end
0

精彩评论

暂无评论...
验证码 换一张
取 消