0

例如,WhereamiViewController拥有CLLocationManager,而CLLocationManager的委托是 WhereamiViewController

当 all has 是一个引用类对象的实例变量时,我对如何WhereamiViewController拥有该类感到困惑。有人可以帮我弄清楚这个概念吗?CLLocationManagerWhereamiViewControllerCLLocationManager

#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
4

1 回答 1

0

CLLocationManager根据文档不保留的代表:

@property( assign , nonatomic) id 委托

因此,您的委托不会被 保留CLLocationManger,因此没有保留循环。

于 2012-08-12T17:11:04.947 回答