カスタムのuitableviewcellを読み込んでメモリリークを引き起こす

私はカスタムの UITableViewCell を使用しています。実際のデバイスでInstrumentsを使用してアプリケーションを実行すると、メモリリークが発生します。リークは、 cellForRowAtIndexPath メソッドを呼び出すと発生します。

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;
}

私はそれをたくさん試しましたが、私のコードはまだ漏れています。私はこのリークがクラ​​ッシュすると信じています。

0
追加された 編集された
ビュー: 1

1 答え

これを試して?

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

nibファイルを読み込む必要がある場合は、 initWithStyle:で実行します。
あなたのメモリリークを引き起こすのが本当に問題なのかどうかはわかりません。 :?

0
追加された