[英]Sending latitude and longitude coordinates to the didFinishLaunchingWithOptions in the app delegate
我有一個此函數可以在我的應用程序委托中獲取較長時間,並且工作正常:
- (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);
}
但是,我正在嘗試在didFinishLaunchingWithOptions部分中將currentLatitude和currentLongitude值發送到應用程序委托的頂部。 我正在嘗試執行此操作,以便可以將這些值傳遞到我在其中設置的另一個viewController中:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
我可以將currentLatitude和currentLongitude值發送到didFinishLaunchingWithOptions部分嗎?
為什么不在第二個viewController中創建currentLatitude
和currentLongitude
?
您可以使用
- (void)newPhysicalLocation:(CLLocation *)location {
// your code here
SecondViewController *viewController = [[SecondViewController alloc] init];
[viewController setLatitude: currentLatitude andLongitude: currentLongitude];
}
要不就
[viewController setCurrentLatitude: currentLatitude];
[viewController setCurrentLongitude: currentLongitude];
根據您對問題的了解,您希望將這些坐標值傳遞給另一個視圖控制器。 如果是這樣,您可以將currentLatitude
和currentLongitude
用作應用程序委托的類變量。 然后,當您在applicationDidFinishLaunchingWithOptions:
調用此函數時applicationDidFinishLaunchingWithOptions:
您可以將值分配給這些類變量。 然后,您可以通過應用程序委托的實例在任何地方訪問這些變量。
注意:如果要在類外訪問變量,則必須合成變量。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.