het laden van een aangepaste uitableviewcell die een geheugenlek veroorzaakt

Ik gebruik een aangepaste UITableViewCell en het geeft me een geheugenlek wanneer ik de applicatie gebruik met behulp van Instruments op een echt apparaat. Het lek treedt op wanneer ik de methode celForRowAtIndexPath aanroept:

static NSString *TipIdentifier = @"TCell"; 

TipsCell *cel = (TipsCell *)[tableView dequeueReusableCellWithIdentifier:TipIdentifier];

if (cel == nil){

    NSLog(@"New Cell Made here");

    cel = (TipsCell *)[[[NSBundle mainBundle] loadNibNamed:@"TipsCell" owner:self options:nil] objectAtIndex:0];

    cel.txtTip.backgroundColor=[UIColor clearColor];
    cel.txtLikes.backgroundColor=[UIColor clearColor];
    cel.txtComments.backgroundColor=[UIColor clearColor];
    cel.txtUserName.backgroundColor=[UIColor clearColor];

    [cel.txtTip setLineBreakMode:UILineBreakModeWordWrap];
    [cel.txtTip setMinimumFontSize:FONT_SIZE];
    [cel.txtTip setNumberOfLines:0];


    cel.backgroundColor = [UIColor colorWithRed:0.113 green:0.42 blue:0.427 alpha:.9];


    //cell.backgroundColor = [UIColor colorWithRed:0.4 green:0.745 blue:0.835 alpha:.9];

    [cel setSelectionStyle:UITableViewCellSelectionStyleGray];

    cel.opaque = NO; 

}    
/*
if ([[QuestionsiLike objectAtIndex:indexPath.row] isEqual:@"1"]) {
    [cell.txtLikes setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
else{
    [cell.txtLikes setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}*/

[cel.txtLikes setTitle:[QuestionsNoLikes objectAtIndex:indexPath.row] forState:UIControlStateNormal];

[cel.txtLikes setTag:indexPath.row];

[cel.txtLikes addTarget:self action:@selector(Like:) forControlEvents:UIControlEventTouchUpInside];



cel.txtComments.text=[QuestionsNoComments objectAtIndex:indexPath.row];

cel.txtTip.text=[QuestionsTxt objectAtIndex:indexPath.row];
cel.txtUserName.text=[QuestionsUN objectAtIndex:indexPath.row];

UIImage *image = [[TKImageCenter sharedImageCenter] imageAtURL:[NSString stringWithFormat:@"http://www.tipntag.com%@",[QuestionsUimg objectAtIndex:indexPath.row]] queueIfNeeded:YES];

[cel.imgUser setImage:image];

image = [[TKImageCenter sharedImageCenter] imageAtURL:[NSString stringWithFormat:@"http://www.tipntag.com%@",[QuestionsRankImg objectAtIndex:indexPath.row]] queueIfNeeded:YES];

[cel.imgRank setImage:image];

NSString *text =[QuestionsTxt objectAtIndex:indexPath.row];// [items objectAtIndex:[indexPath row]];

CGSize constraint = CGSizeMake(220, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[cel.txtTip setFrame:CGRectMake(70, 5, 220 , MAX(size.height, 30.0f))];

//cell.txtLikes.text=[QuestionsNoLikes objectAtIndex:indexPath.row];
//cell.txtComments.text=[QuestionsNoComments objectAtIndex:indexPath.row];

NSString *tstr=[NSString stringWithFormat:@"%@",[QuestionsLat objectAtIndex:indexPath.row]];
NSLog(tstr);

if ([tstr isEqual:@""]) {
    [cel.imgMap setEnabled:NO];
    [cel.lblDistance setHidden:YES];
    [cel.GetDirections setHidden:YES];
    [cel.imgDistance setHidden:YES];
}
else{
    [cel.imgMap setEnabled:YES];

    [cel.imgMap setTag:indexPath.row];

    [cel.imgMap addTarget:self action:@selector(GoToMap:) forControlEvents:UIControlEventTouchUpInside];

    NSLog(@"%@",[QuestionsDistance objectAtIndex:indexPath.row]);

    [cel.imgDistance setHidden:NO];
    [cel.lblDistance setHidden:NO];

    NSString *tmp2=[[NSString alloc]initWithFormat:[NSString stringWithFormat:@"%@",[QuestionsDistance objectAtIndex:indexPath.row]]];

    NSString *tmp=[[NSString alloc] initWithFormat:@"%@ mi",[tmp2 substringToIndex:4]];

    [tmp2 release];


    [cel.lblDistance setText:[NSString stringWithString:tmp]];

    [tmp release];

    [cel.GetDirections setHidden:NO];

    end.latitude=[[QuestionsLat objectAtIndex:indexPath.row] floatValue];
    end.longitude=[[QuestionsLong objectAtIndex:indexPath.row] floatValue];

    [cel.GetDirections setTag:indexPath.row];

    [cel.GetDirections addTarget:self action:@selector(getDirection:) forControlEvents:UIControlEventTouchUpInside];



}

if ([[QuestionsiLike objectAtIndex:indexPath.row] intValue]==0) {

    [[cel txtLikes] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}else
{
    [[cel txtLikes] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
NSLog(@"%@",[QuestionsLat objectAtIndex:indexPath.row]);



return cel;
}

Ik heb er veel mee geprobeerd, maar mijn code lekt nog steeds. Ik geloof dat dit lek resulteert in een crash.

0

1 antwoord

Probeer dit?

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
  cell = [[[TableViewCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
TableViewCustomCell * customCell = (TableViewCustomCell *)cell;

En als u het nib-bestand wel moet laden, voert u het uit in initWithStyle: .
Ik weet niet zeker of dit het probleem is waardoor je geheugen lekt. :?

0
toegevoegd