【发布时间】:2013-01-23 06:49:38
【问题描述】:
我的方法中有一个 View 对象突然变为 nil。
我没有使用 ARC
不涉及线程
发生的事情是,我第一次调用 1stmethod 方法时一切正常,并且保留了对 livecoreSettings 的引用。
接下来,当我调用 2ndmethod 方法时,还保留了 livecoreSettings 引用,但是当委托方法被激活时,该变量的引用丢失了..不知道为什么...
@interface XY {
LiveScoreSettingsView * livescoreSettings; // initialisation in .h file inside
}
@end
@implementation
// 1st method
- (void)1stmethod:(id) callingClass username:(NSString*)username {
livescoreSettings=callingClass; // retain count increases to 1
isLivescoresSettingsView = YES;
//.... some code where the above livescoreSettings variables are not used ... //
}
// 2nd method
- (void)2ndmethod:(id) callingClass username:(NSString*)username matchid:(NSString *)matchid eventType:(NSString *) eventType add:(NSString *) add {
livescoreSettings=callingClass;
isLivescoresSettingsView = YES;
addEventToList = YES;
//.... some code where the above livescoreSettings variables are not used ... //
}
// delegate method thats activated when the response comes
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
// the block where the data is sent to a particular view to reload table
else if(isLivescoresSettingsView== YES || addEventToList == YES) {
isLivescoresSettingsView=NO;
addEventToList = NO;
//.... some code where the above livescoreSettings variables are not used ... //
if(success)
NSLog(@"No Errors with retain count = %d ", [livescoreSettings retainCount]);
else
NSLog(@"Error Error Error!!!");
[livescoreSettings.tableView reloadData];
// when **2ndmethod** is called there's no memory reference to livescoreSettings, tableView delegate methods are not called which is obvious. But not sure why the retain count is reducing abruptly.
}
}
@end
【问题讨论】:
-
livescoreSettings也是一个实例变量吗? -
No ARC...livescoreSettings 不是实例变量。它在 .h 文件中声明
-
no.. 不涉及线程
-
好的,如果
lovescoreSettings不是实例变量,那么它在哪里定义?这就像 20 个问题,不应该是这样! -
如果您在我的代码中看到注释,我已经提到了与.h 文件中声明的相同@interface
标签: xcode reference ios6 retaincount