将纬度和经度坐标发送到应用程序委托中的 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 部分吗?
I have a this function to grab the lat and long in my app delegate, and it's working fine:
- (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);
}
However, I'm trying to send the currentLatitude and currentLongitude values to the top of the app delegate in the didFinishLaunchingWithOptions section. I'm trying to do this so I can pass those values to another viewController in which I have set up:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
Can I send the currentLatitude and currentLongitude values to the didFinishLaunchingWithOptions section?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在第二个 viewController 中创建
currentLatitude
和currentLongitude
呢?您可以使用
或仅
Why not create a
currentLatitude
andcurrentLongitude
in the second viewController?You can use
or just
根据我对你的问题的理解,你想将这些坐标值传递给另一个视图控制器。如果是这种情况,您可以将 currentLatitude 和 currentLongitude 作为应用程序委托的类变量。然后,当您在 applicationDidFinishLaunchingWithOptions: 中调用此函数时,您可以将值分配给这些类变量。然后您可以通过应用程序委托的实例在任何地方访问这些变量。
注意:如果您想在类外部访问变量,则必须合成变量。
希望这有帮助
From what I understood from your question, you want to pass those coordinate values to another view controller. If thats the case u can make the
currentLatitude
andcurrentLongitude
as class variables of the app delegate. Then when u call this function inapplicationDidFinishLaunchingWithOptions:
you can assign the values to these class variables. Then u can access these variables anywhere through an instance of the app delegate.Note: You have to synthesize the variables if u want to access them outside the class.
Hope this helps