2009-04-13 21 views
0

テーブルビューセルのすべてのエントリに対して、右にボタンを、次にテキストに左のボタンが必要です。ボタンのクリックイベントでは、テキストを変更する必要があります(左/右ボタンをクリックします)。テキスト条件に応じて、いずれかのボタンを削除する必要があります。私はcellForRowAtIndexPathメソッドを使用してボタンを削除することができません。私はUITableViewCellをサブクラス化し、メソッド-prepareForReuseを使用しようとしましたが、セルをリセットできません。任意のアイデアどのように私はこれを達成するのですか?または、このボタンを非表示にする方法や、非表示にする方法がありますか?あなたがしたいと思う何UITableViewCellが更新されない

NSString *CellIdentifier = [[NSString alloc] initWithFormat:@"Cell%d",indexPath.row]; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 


[self.tableView clearsContextBeforeDrawing]; 
NSString *str = [listOfItems objectAtIndex:indexPath.row]; 

    cell.text = [listOfItems objectAtIndex:indexPath.row]; 
    cell.textColor = [UIColor blueColor]; 
    cell.font = [UIFont systemFontOfSize:14]; 

     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
     UIImage *image = [UIImage imageNamed:@"Arrow_Right.png"]; 
     CGRect frame = CGRectMake(290, 5, image.size.width, image.size.height); 
     button.frame = frame; 
     [button setBackgroundImage:image forState:UIControlStateNormal]; 
     button.backgroundColor = [UIColor clearColor]; 
     [button addTarget:self action:@selector(rightArrow_clicked:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell addSubview:button]; 

     UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
     UIImage *img = [UIImage imageNamed:@"Arrow_Left.png"]; 
     CGRect frame1 = CGRectMake(5, 5, img.size.width, img.size.height); 
     button1.frame = frame1; 
     [button1 setBackgroundImage:img forState:UIControlStateNormal]; 
     button1.backgroundColor = [UIColor clearColor]; 
     [button1 addTarget:self action:@selector(leftArrow_clicked:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell addSubview:button1]; 

    if([str isEqual:@" abc "]) 
     [button setEnabled:NO]; 
    if([str isEqual:@" pqr "]) 
     [button1 setEnabled:NO]; 
+0

はい再利用可能なセルです。 -prepareForReuseメソッドでどのようにリセットするのですか? – Neo

答えて

1

は、サブクラスUITableViewCellのある、そして、彼らは一度だけ追加しているように、init方法でサブビューを追加します。

ほとんどの場合、再利用可能なセルにサブビューを追加している可能性があります。これは、以前の使用時に既にボタンが表示されている可能性があります。また、ボタンを「不可視」に設定することもできます。

[button setHidden:YES]; 
関連する問題