Iphone 设置CLLocationManager的委托(两种不同的方式,是否相等?)
使用CLLocationManager编写教程,其中我在init方法中设置了委托:Iphone 设置CLLocationManager的委托(两种不同的方式,是否相等?),iphone,objective-c,delegates,cllocationmanager,Iphone,Objective C,Delegates,Cllocationmanager,使用CLLocationManager编写教程,其中我在init方法中设置了委托: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { locationManager = [[CLLo
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
return self;
}
设置代理:
[locationManager setDelegate:self];
在另一个教程中,我在头文件中设置了代理:
@interface MyViewController : UIViewController <CLLocationManagerDelegate>
@接口MyViewController:UIViewController
他们平等吗?有什么区别(如果有的话)?这是两种不同的东西 这是一个很好的例子
[locationManager setDelegate:self]
只设置对象委托,因此CLLocationManager可以调用实现的委托方法。要使其正常工作,self
必须符合CLLocationManagerDelegate协议
换句话说,你需要同时做这两件事。这是两件不同的事情 这是一个很好的例子
[locationManager setDelegate:self]
只设置对象委托,因此CLLocationManager可以调用实现的委托方法。要使其正常工作,self
必须符合CLLocationManagerDelegate协议
换句话说,您需要同时执行这两项操作。如果您想要实现并从CLLocationManager的代表处获得回调,则需要同时执行这两项操作 您可以在标题中指定它
@interface MyViewController : UIViewController <CLLocationManagerDelegate>
您告诉您的CLLocationManager(locationManager)实例MyViewController(self)将是委托,并且它应该调用您已经实现的所有已实现的CLLocationManagerLegate方法(如果需要)如果您要实现并从CLLocationManager的委托处获得回调,您将需要这两个方法 您可以在标题中指定它
@interface MyViewController : UIViewController <CLLocationManagerDelegate>
您告诉您的CLLocationManager(locationManager)实例MyViewController(self)将是委托,并且它应该调用您已实现的所有已实现的CLLocationManagerDelegate方法(如果需要)如果将委托设置为不符合要求的类,则会收到编译器警告。如果将委托设置为不符合要求的类,则会收到编译器警告。谢谢你们两位的精彩回答。谢谢你们两位的精彩回答。