2012-05-10 9 views
2

私のアプリでは、imageViewとUILabelが1つあります。 ImageViewの場合、私はそれにasynch Imageを割り当てて、うまくいきますが、最初と最後の行のラベルは、テーブルをスクロールすると重なってしまいます。あなたはそれが新鮮に作成または再利用したかどうかのセルにnameLabelを追加しているcellForRowAtIndexPathのReusableCellWithIdentifier問題

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

    productObject=[appDelegate.productArray objectAtIndex:indexPath.row]; 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    UILabel *nameLabel; 
    if (cell == nil) 
    { 

     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero  reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleBlue; 

    } 

    else 
    { 

     AsyncImageView* oldImage = (AsyncImageView*)[cell.contentView viewWithTag:999]; 
     [oldImage removeFromSuperview]; 
    } 

    CGRect nameLabelRect = CGRectMake(70,80,150,15); 
    nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];  
    nameLabel.text = [NSString stringWithFormat:@"%@",productObject.productname]; 
    nameLabel.textAlignment = UITextAlignmentCenter; 
    nameLabel.lineBreakMode = UILineBreakModeCharacterWrap; 
    nameLabel.font = [UIFont boldSystemFontOfSize:15]; 
    nameLabel.backgroundColor = [UIColor clearColor]; 
    [cell.contentView addSubview: nameLabel]; 

    } 

答えて

7

はseprateの識別子を使用して

NSString *cellIdentifier = [NSString stringWithFormat:@"cell%i",indexpath.row]; 

か、単に以下のようなものは、私は専門家ではないですが、二番目が働いて、単にそれらにセルとデータを作る

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

UITableViewCell *cell = [[UITableViewCell alloc]init]; 
UIButton *favBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
favBtn.frame = CGRectMake(0, 0, 50, 50); 
favBtn.backgroundColor = [UIColor clearColor]; 
favBtn.showsTouchWhenHighlighted = YES; 
favBtn.tag = indexPath.row; 

UIButton *arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
arrowBtn.frame = CGRectMake(280, 26, 25, 25); 
arrowBtn.backgroundColor = [UIColor clearColor]; 
arrowBtn.showsTouchWhenHighlighted = YES; 
[arrowBtn setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal]; 

UILabel *date = [[UILabel alloc]initWithFrame:CGRectMake(55, 26, 250, 25)]; 
date.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:0] size:15]; 
date.text = ann.title; 
date.textColor = [UIColor blackColor]; 
date.backgroundColor = [UIColor clearColor]; 

[cell.contentView addSubview:favBtn]; 
[cell.contentView addSubview:date]; 
[cell.contentView addSubview:arrowBtn]; 


    return cell; 
} 

reuseabilityを使用してはいけません私のためにかなりよくうまくいってくれることを願っています

+0

ありがとう私は問題を解決しました!!!!! – USK

+0

:)あなたのために幸せ – superGokuN

+0

ありがとうこれは完璧なソリューションです.. – Gaurav

0

は、ここに私のコードです。そう、ええ、あなたが再利用された細胞を見るためにスクロールするたびに、別のラベルを積み重ねます。すべてのセルのための

関連する問題