我在 xcode 中有一个 tabbar 项目,在第一个视图中我需要找到我的 GPS 位置,我需要在 appdelegate 上的两个变量上保存经度和纬度。这里有一些代码:
第一视图控制器.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface FirstViewController : UIViewController <CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
第一视图控制器.m
#import "FirstViewController.h"
#import "CampeggiandoAppDelegate.h"
#import <CoreLocation/CoreLocation.h>
@interface FirstViewController ()
@end
@implementation FirstViewController
@synthesize locationManager;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.image = [UIImage imageNamed:@"ic_home2"];
self.tabBarItem.title=@"Home";
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
self.locationManager.distanceFilter=500.0f;
self.locationManager.desiredAccuracy=kCLLocationAccuracyHundredMeters;
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CampeggiandoAppDelegate *appDelegate=(CampeggiandoAppDelegate*)[[UIApplication sharedApplication]delegate];
appDelegate.latitudineDel=[NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude];
appDelegate.longitudineDel=[NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude];
}
当我运行编译器并出现最合适的视图时,应用程序损坏并出现此异常:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[AppDelegate setLatitudineDel:]:无法识别的选择器发送到实例 0x84210b0”
有什么帮助吗?谢谢。