0

次のコードはどれほど間違っている可能性がありますか。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    for (id currentObject in array) {

        if ([currentObject isKindOfClass:[self class]]) {
            self = [currentObject retain];
        }
    }

    return self;
}

nibファイルからカスタムUITableViewCellを起動しようとしていますが、問題はLeaksInstrumentsが内部にリークがあると言っていることです。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

    CPVideoGenTVCell *cell = (CPVideoGenTVCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        cell = [[[CPVideoGenTVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        cell.titleLbl.textColor = [UIColor colorWithRed:0.992 green:0.933 blue:0.0 alpha:1.0];

    }

    CPTempVideo *aVideo = [self.videos objectAtIndex:indexPath.row];

    cell.seasonLbl.text = [NSString stringWithFormat:@"Season %@", [self romanNumberFromArabic:aVideo.season]];
    cell.titleLbl.text = [NSString stringWithFormat:@"%2i - \"%@\"",aVideo.idVideo, aVideo.chapterName];
    cell.managedImg.url = aVideo.thumbnail;

    [[CPDataManager sharedDataManager] manageImage:cell.managedImg];

    return cell;
}
4

2 に答える 2

0

問題は保持にあると思いますが、なぜinitWithStyleでこのクレイジーなことをしているのか理解できません..

if ([currentObject isKindOfClass:[self class]]) {
  self = currentObject;
}
于 2012-05-09T23:11:31.383 に答える
0

私が見つけた代替手段があります:

+ (id)cellWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    NSArray *array = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    for (id currentObject in array) {

        if ([currentObject isKindOfClass:[self class]]) {
            return currentObject;
        }
    }

    return nil;
}

自動解放されたオブジェクトを返し、cellForRowAtIndexPath 内でそれを処理します。

CPTempHeadCell *headCell = (CPTempHeadCell *)[tableView dequeueReusableCellWithIdentifier:HeadCellIdentifier];
if (headCell == nil) {

    headCell = [CPVideoGenTVCell cellWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier:CellIdentifier];
于 2012-05-11T16:43:16.927 に答える