将viewcontroller连接到代理类-CLLocationManager/iOS8
尝试将视图控制器链接到委托类(实现CLLocation回调)时,初始化委托时出错 我的VC.h:将viewcontroller连接到代理类-CLLocationManager/iOS8,ios,objective-c,iphone,uiviewcontroller,delegates,Ios,Objective C,Iphone,Uiviewcontroller,Delegates,尝试将视图控制器链接到委托类(实现CLLocation回调)时,初始化委托时出错 我的VC.h: @interface ViewController : UIViewController <MyLocationControllerDelegate> { MyLocationController *CLController; } 我注意到这个错误在以前的iOS版本中没有出现 谢谢你的帮助 根据,MyLocationController必须符合CLLocationManagerDe
@interface ViewController : UIViewController <MyLocationControllerDelegate> {
MyLocationController *CLController;
}
我注意到这个错误在以前的iOS版本中没有出现
谢谢你的帮助 根据,MyLocationController
必须符合CLLocationManagerDelegate
@interface MyLocationController: NSObject <CLLocationManagerDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, weak) id delegate;
@end
@接口MyLocationController:NSObject
@属性(非原子,强)CLLocationManager*locationManager;
@属性(非原子,弱)id委托;
@结束
作为旁注,您不需要为属性
locationManager
和delegate
声明IVAR。iVars\u locationManager
和\u委托将自动为您生成。感谢@jeffery的编辑!还不知道怎么做..您的协议声明为空。您的MyLocationControllerDelegate定义在哪里?谢谢,就这样!附带问题,由于某种原因,当回调函数didUpdateLocations:位于单独的类中时,我没有收到任何回调。你知道会出什么问题吗?我用上下文的更多信息更新了我的描述。谢谢你的帮助!
- (id)init
{
self = [super init];
if(self != nil) {
self.locationManager = [[CLLocationManager alloc] init]; // Create new instance of locationManager
self.locationManager.delegate = self; // Set the delegate as self.
}
return self;
}
@interface MyLocationController: NSObject <CLLocationManagerDelegate>
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, weak) id delegate;
@end