1

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

ZIFollowerRequestsCell.m:34:5: 返回 'self' 而它未设置为 '[(super or self) init...]' 的结果

#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

谢谢你的帮助。

4

1 回答 1

2

您正在分配 self 两次。第二次,嗯,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; 
}
于 2013-10-03T16:35:48.777 回答