发送纬度和经度坐标的didFinishLaunchingWithOptions在应用程序的委托

我有这个功能来获取经纬度和长在我的应用程序委托,和它的正常工作:

- (void)newPhysicalLocation:(CLLocation *)location { // Store for later use self.lastKnownLocation = location; // Remove spinner from view for (UIView *v in [self.viewController.view subviews]) { if ([v class] == [UIActivityIndicatorView class]) { [v removeFromSuperview]; break; } } // Alert user UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Found" message:[NSString stringWithFormat:@"Found physical location. %f %f", self.lastKnownLocation.coordinate.latitude, self.lastKnownLocation.coordinate.longitude] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; [alert release]; currentLatitude = (self.lastKnownLocation.coordinate.latitude); NSLog(@"current latitude: %f",self.lastKnownLocation.coordinate.latitude); currentLongitude = (self.lastKnownLocation.coordinate.longitude); NSLog(@"current longitude: %f",currentLongitude); }

不过,我想在currentLatitude和currentLongitude值发送到在didFinishLaunchingWithOptions部分应用程序委托的顶部。 我试图做到这一点,所以我可以通过这些值到另一个的viewController中,我已经设置了:

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

我可以发送currentLatitude和currentLongitude值的didFinishLaunchingWithOptions部分?

--------------解决方案-------------

从我从你的问题的理解,要将这些坐标值传递给另一个视图控制器。 如果多数民众赞成的情况下ü可以使currentLatitudecurrentLongitude作为应用程序委托的类变量。 然后,当u调用这个函数applicationDidFinishLaunchingWithOptions:您可以将值赋给这些类变量。 然后ü可通过应用程序委托的一个实例,在任何地方访问这些变量。

注意:您要综合变量如果u想访问它们的类之外。

希望这可以帮助

为什么不创建一个currentLatitudecurrentLongitude在第二的viewController?

您可以使用

- (void)newPhysicalLocation:(CLLocation *)location {
// your code here

SecondViewController *viewController = [[SecondViewController alloc] init];
[viewController setLatitude: currentLatitude andLongitude: currentLongitude];
}

或者只是

[viewController setCurrentLatitude: currentLatitude];
[viewController setCurrentLongitude: currentLongitude];

分类:iphone 时间:2012-03-28 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.733 (s). 10 q(s)