Objective c 目标-C–设置后保留的属性为零?
我有两门课: 一个UIViewController和一个类,该类是NSObject的子类,它充当一个名为OfficesParser的下载帮助器类。OfficesParser正在使用ASIHTTPRequest,我将下载请求的委托设置为我的UIViewController 编辑:UIViewController的界面:Objective c 目标-C–设置后保留的属性为零?,objective-c,delegates,null,Objective C,Delegates,Null,我有两门课: 一个UIViewController和一个类,该类是NSObject的子类,它充当一个名为OfficesParser的下载帮助器类。OfficesParser正在使用ASIHTTPRequest,我将下载请求的委托设置为我的UIViewController 编辑:UIViewController的界面: @interface OfficesViewController : UIViewController <UITableViewDelegate, UITableViewDa
@interface OfficesViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, ASIHTTPRequestDelegate> {
OfficesParser *officesParser;
}
@property (nonatomic, retain) OfficesParser *officesParser;
@end
然后在视图出现之前,我调用my OfficesParser对象为我下载一些数据:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.officesParser doNetworkOperations];
}
在UIViewController中,我还设置了相应的委托方法,以便在数据下载后处理数据。我特别感兴趣的是这个委托方法,它将在下载队列中处理完所有数据后运行。我可以从日志中看到委托方法正在运行。但出于某种原因,这里的self.officesParser为零
- (void)queueFinished:(ASINetworkQueue *)queue {
DLog(@"queueFinished running");
[self.officesParser test]; // test will not get called because self.officesParser is nil
}
办公室在哪里?显示声明officesParser属性的代码。你有@synthesize等吗?我添加了@interface代码,是的,属性是@synthesize。否则,我在-viewDidLoad中调用self.officesParser将无法工作。只有两种可能的情况:-或者您从未实际分配officesParser,因此没有调用-viewDidLoad,[[officesParser alloc]init]返回nil,或者-viewDidLoad是在OfficesViewController的不同实例上调用的,而不是-queueFinished,或者在一些代码中,您没有显示您正在将officesParser设置为nil。这确实是一个奇怪的问题。我知道调用viewDidLoad是因为否则我将无法调用方法doNetworkOperations,事实上我知道该方法也会被调用,因为委托方法queueFinished:将在日志中输出。但由于某些原因,当queueFinished:正在运行self.officesParser时,它是空的。我刚才注意到self中所有的实例变量都是空的。似乎当委托方法queueFinished:正在运行时,它会丢失与self对象的连接?请尝试将self的地址记录在-viewDidLoad中,-viewwillbeen和-queueFinished中。差不多NSLog@self是%p,self;确保它们是一样的。
- (void)queueFinished:(ASINetworkQueue *)queue {
DLog(@"queueFinished running");
[self.officesParser test]; // test will not get called because self.officesParser is nil
}