在未设置为'[(超级或自​​我)初始化...]的结果时返回“自我”

时间:2013-10-03 16:11:58

标签: objective-c cocoa-touch memory-leaks clang-static-analyzer

有人知道为什么Xcode 5 Analyze抱怨这个:

  

ZIFollowerRequestsCell.m:34:5:在未设置为“self”时返回   “[(超级或自​​我)初始化......]”

的结果
#import "ZIFollowerRequestsCell.h"

@implementation ZIFollowerRequestsCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"ZIFollowerRequestsCell" owner:self options:nil];
        self = [nibArray objectAtIndex:0];

        self.profileImageView.image = nil;
        self.profileImageView.userInteractionEnabled = YES;
   }
   return self;
}

@end

@interface ZIFollowerRequestsCell : UITableViewCell <UIGestureRecognizerDelegate>
@end

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

你要两次分配自己。第二次,嗯,Xcode所说的。此外,最好不要在构造函数中使用self.variable,只需使用_variable即可。

你注册了你的手机吗?假设您有一个ZIFollowerRequestsCell.xib,其根视图是具有类ZIFollowerRequestsCell的单元格,请在视图控制器中尝试:

NSString * const REUSE_ID_CELL = @"ZIFollowerRequestsCell";

- (void)registerNIBs
{
    NSBundle *classBundle = [NSBundle bundleForClass:[ZIFollowerRequestsCell class]];
    UINib *nib = [UINib nibWithNibName:REUSE_ID_CELL bundle:classBundle];
    [[self tableView] registerNib:topNib forCellReuseIdentifier:REUSE_ID_CELL];
}

- (NSString *)reuseIdentifierForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return REUSE_ID_CELL; 
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *reuseID = [self reuseIdentifierForRowAtIndexPath:indexPath];
    UITableViewCell *cell = [[self tableView] dequeueReusableCellWithIdentifier:reuseID];
    return cell; 
}