我目前正在完成关于#Augmented Reality 的 Ray Wenderlich iOS 教程,我遇到了一个关于在 MainViewController 界面中找不到 setLocationManger 的问题?我该如何解决?
我不明白,因为我认为这包含在 CoreLocation/Corelocation.h 类中。
#import "MainViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MainViewController () <CLLocationManagerDelegate, MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapViewPointer;
@property (nonatomic, strong) CLLocationManager *locationManagerPointer;
@end
@implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Roll Tide
[self setLocationManager:[[CLLocationManager alloc] init]];
[_locationManagerPointer setDelegate:self];
[_locationManagerPointer setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[_locationManagerPointer startUpdatingLocation];
最佳答案
@property(非原子,强)CLLocationManager *locationManagerPointer;
将 locationManagerPointer
重命名为 locationManager
或将 setter 调用为
[self setLocationManagerPointer:[[CLLocationManager alloc] init]];
当您声明属性时,会自动创建 setter 和 getter。
如果您将属性声明为 @property NSString *userName
,则会创建一个具有 setUserName
方法的 setter 和 getter userName
方法。您可以通过 [self setUserName:@"fooBar"]
和 [self userName]
访问它们。错误的原因是您的属性名称与 setter 的名称不同。
关于iOS编译错误: No visible @interface for 'setLocationManager' declares the selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29444197/