简体   繁体   English

“self”时使用的实例变量未通过Analyzer设置为“[(super或self)init ...]”的结果

[英]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.

相关问题 'self'时使用的实例变量未设置为[(super或self)init ...]的结果 - Instance variable used while 'self' is not set to the result of [(super or self) init…] “self”时使用的实例变量未设置为结果 - Instance variable used while 'self' is not set to the result of 当我初始化自定义单元格时,它没有设置为'[(super或self)init ...]'的结果时返回'self' - Returning 'self' while it is not set to the result of '[(super or self) init…]' when I initialize custom cell 在我的自定义alloc方法中未将其设置为'[((super或self)init…])的结果时返回'self' - Returning 'self' while it is not set to the result of '[(super or self) init…]' in my custom alloc method self = [super init]重访 - self = [super init] revisited [self init]和self = [super init]之间的差异 - Difference between [ self init ] and self = [ super init ] RealmSwift初始值设定项:在super.init调用之前自行使用 - RealmSwift initializer: self used before super.init call 在super.init调用之前使用“ self”,并且在super.init调用中未初始化属性 - 'self' used before super.init call and property not initialized at super.init call 当 init() 也初始化成员变量并引用“self”时,super.init() 放在哪里 - Where to put super.init() when init() also initializes member variable and references "self" Failable Init - 在初始化之前使用的变量“self.customerType” - Failable Init - Variable 'self.customerType' used before being initialized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM