DidUpdateLocation无法识别的选择器发送到实例

时间:2014-03-29 17:20:35

标签: ios objective-c cllocationmanager

我是iOS开发的新手,我目前面临一个我不知道答案的问题。我现在已经挣扎了一段时间,所以我希望我能在这里得到一些帮助。

使用LocationManager类时问题仍然存在。我制作了一个单身人士,每个班级都可以访问。这似乎有效,但由于某种原因,我发现了一个未被识别的选择器发送到实例'在我的DidUpdateLoation委托中。有人可以解释一下我做错了吗?

错误:

由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' - [MyPFQueryTableViewController locationControllerDidUpdateLocation:]:无法识别的选择器发送到实例0x805e8c0'

LocationController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@protocol SCLocationControllerDelegate

- (void)locationControllerDidUpdateLocation:(CLLocation *)location;

@end

@interface SCLocationController : UIViewController

@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) CLLocation *location;

@property (weak, nonatomic) id delegate;

+ (SCLocationController *)sharedController;

@end

LocationController.m

#import "LocationController.h"

@interface SCLocationController ()

@end

@implementation SCLocationController

+ (SCLocationController *)sharedController
{
    static SCLocationController *sharedController = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedController = [[self alloc]init];
    });

    return sharedController;
}

- (id)init
{
    self = [super init];
    if (self) {
        _locationManager = [[CLLocationManager alloc]init];
        _locationManager.delegate = self;
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.distanceFilter = 30; // Meters.
    }
    return self;
}

#pragma mark - Location Manager

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    [self.delegate locationControllerDidUpdateLocation:locations.lastObject];
    [self setLocation:locations.lastObject];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    // ...
}

@end

用法:

- (void)viewWillAppear:(BOOL)animated {
    [[SCLocationController sharedController]setDelegate:self];
    [[SCLocationController sharedController].locationManager startUpdatingLocation];
    [super viewWillAppear:animated];
} 

提前谢谢!

0 个答案:

没有答案