例如,
WhereamiViewController
拥有CLLocationManager
,而CLLocationManager
的委托是WhereamiViewController
。
当 all has 是一个引用类对象的实例变量时,我对如何WhereamiViewController
拥有该类感到困惑。有人可以帮我弄清楚这个概念吗?CLLocationManager
WhereamiViewController
CLLocationManager
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@end
#import "WhereamiViewController.h"
@implementation WhereamiViewController
-(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;
}
@end