【发布时间】:2011-10-21 16:18:41
【问题描述】:
我无法触发我的委托方法。我有以下代码:
@class Location;
@protocol LocationDelegate
- (void)location:(Location*)location foundLocation:(CLLocation*)location;
- (void)location:(Location*)location failedToLocateUserWithError:(NSError*)error;
@end
@interface Location : NSObject {
__unsafe_unretained id <LocationDelegate> delegate;
}
@property (nonatomic, assign) id <LocationDelegate> delegate;
@end
...
@implementation Location
@synthesize delegate;
- (void)startUpdatingLocation {
NSLog(@"%@", delegate); // prints '(null)'
...
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"%@", delegate); // prints '(null)'
[delegate location:self foundLocation:newLocation];
}
@end
以前在其他项目中工作得很好,所以想知道它是否与 ARC 有关?分配Location 的对象确实符合LocationDelegate。我还将代表设置为自我。但是委托方法没有触发,如果我输出它,它就是空的。
谢谢
【问题讨论】:
标签: ios delegates automatic-ref-counting