例如,
WhereamiViewController
拥有CLLocationManager
, 并且CLLocationManager
的代表是WhereamiViewController
。
当所有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
答案 0 :(得分:0)
CLLocationManager
的代表未被保留
@property( 分配 ,非原子)id委托
因此,您的委托不会被CLLocationManger
保留,因此没有保留循环。