0
例如,
WhereamiViewController
擁有CLLocationManager
, 和CLLocationManager
的代表是WhereamiViewController
。混亂上代表所有權
我在WhereamiViewController
如何擁有當所有WhereamiViewController
已經是一個實例變量指的是類CLLocationManager
的對象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
弱引用,我的朋友,弱引用。 – 2012-08-12 17:09:40
WhereamiViewController不擁有CLLocationManager類,它擁有實例locationManager,因爲它使用alloc init創建它。 – rdelmar 2012-08-12 17:09:57