简体   繁体   中英

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:

Instance variable used while 'self' is not set to the result of [(super or 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).

You should also never need to grub through the IB file like that. 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.

It's because of self = (ClientInfoView *)currentObject; . I think there's some confusion as to how to connect to your object from within your 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:

NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ClientInfoView" 
                                                         owner:self 
                                                       options:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM