[英]Instance variable used while 'self' is not set to the result of '[(super or self) init…]' via Analyzer
When i test my code via Analyzer then got: 当我通过Analyzer测试我的代码然后得到:
Instance variable used while 'self' is not set to the result of [(super or self) init…]
'self'时使用的实例变量未设置为[(super或self)init ...]的结果
My code: 我的代码:
self = [super init];//initWithFrame:frame];
if (self)
{
tickerSymbol = [object valueForKey:@"TickerSymbol"];
url = [object valueForKey:@"URL"];
rssFeed = [object valueForKey:@"RSSFeed"];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ClientInfoView"
owner:nil
options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[ClientInfoView class]])
{
self = (ClientInfoView *)currentObject;
break;
}
}
[self.clientNameLabel setText:[clientObject valueForKey:@"Name"]];
[self.symbolLabel setText:[object valueForKey:@"TickerSymbol"]];
//[self loadHistoricalInfo];
self.getStock = [GetStockValue stockValueWithDelegate:self];
[self loadInfo:object clientObject:clientObject];
[self layoutLabels];
}
return self;
self = (ClientInfoView *)currentObject;
That doesn't make any sense. 这没有任何意义。 You should never be re-assigning
self
save for to the result of [super init...]
(and in the case of some advanced techniques, which this isn't). 你永远不应该为
[super init...]
的结果重新分配self
保存(并且在一些高级技术的情况下,这不是)。
You should also never need to grub through the IB file like that. 您也应该永远不需要像这样浏览IB文件。 Create an outlet and make a connection, then use the outlet directly in your code.
创建一个插座并建立连接,然后直接在您的代码中使用插座。
Note that, in general, you shouldn't load interface in init
methods. 请注意,通常,您不应在
init
方法中加载接口。
It's because of self = (ClientInfoView *)currentObject;
这是因为
self = (ClientInfoView *)currentObject;
. 。 I think there's some confusion as to how to connect to your object from within your
nib
. 我认为如何从你的
nib
内连接到你的对象有一些混乱。 Instead of instantiating an object within the nib file and trying to swap your object for it, try connecting to File's Owner
from within your nib
, and then set yourself as the owner: 而不是在nib文件中实例化对象并尝试交换对象,尝试从您的
nib
内连接到File's Owner
,然后将自己设置为所有者:
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ClientInfoView"
owner:self
options:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.