xcode에 tabbar 프로젝트가 있고 첫 번째보기에서 GPS 위치를 찾아야하고 appdelegate의 두 변수에 경도와 위도를 저장해야합니다. 여기에 몇 가지 코드 :CLLocation이 작동하지 않습니다 - 인식 할 수없는 선택기를 인스턴스로 보냄
FirstViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface FirstViewController : UIViewController <CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
FirstViewController.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"];
[email protected]"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];
}
나는 컴파일러와 fitst보기 응용 프로그램이 파산 나타나고이 예외가 나타납니다 실행하면 :
을캐치되지 않은 예외로 인해 앱 종료 'NSInvalidArgumentException', 이유 -
어떤 도움 '[AppDelegate에 setLatitudineDel :] 인스턴스 0x84210b0에 인식 할 수없는 선택기를 보내'? 감사. 그래서 그 예에 대한 세터가없는
@interface CampeggiandoAppDelegate : UIResponder <UIApplicationDelegate> {
// ...
NSString *latitudineDel;
NSString *longitudineDel
// ...
}
@end
:
@interface CampeggiandoAppDelegate : UIResponder <UIApplicationDelegate> {
// ...
// some ivars
// ...
}
@property (nonatomic, strong) NSString *latitudineDel;
@property (nonatomic, strong) NSString *longitudineDel;
@end
당신이이 순간을 위해있는 것은 이것이다 :
'CampeggiandoAppDelegate' 클래스는'latitudineDel '속성을 갖지 않습니다. 'CLLocationManager'와 함께 잘못되지 않았습니다 – rckoenes
틀렸어. CampeggiandoAppDelegate에 NSString latitudineDel 및 longitudinalDel이 있습니다 – gabboSonc
오류 'CampeggiandoAppDelegate'에는'latitudineDel '속성에 대한 설정자가 없습니다. 읽기 전용으로 설정해야하는 속성이거나 속성이 전혀 정의되지 않은 속성입니다. – rckoenes