0

スクロール後に画像を削除するにチェックを入れます。
セルを再利用する必要があり、didselectrowメソッドも使用したくありません。これは、1 つのセルに複数のボタンがあり、これがスタックオーバーフロー用に作成したサンプルであるためです。

テーブルビューのスクリーンショット 私はグーグルでたくさん検索しましたが、どうしようもありませんでした。

これが私のサンプルコードです

//
//  TVViewController.h
//  tableviewcheck



#import <UIKit/UIKit.h>

@interface TVViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{

    UITableView *sampleTableView;
    UIImageView * imageView1;
    UIButton* aButton1;
    UIImageView *imageViewchk1;
    int tag;

}

@property (nonatomic, strong) IBOutlet UITableView *sampleTableView;

@end


//  TVViewController.m
//  tableviewcheck

#import "TVViewController.h"

@interface TVViewController ()

@end

@implementation TVViewController
@synthesize sampleTableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    // Return the number of rows in the section.
    // Usually the number of items in your array (the one that holds your list)
    //  NSLog(@"selected %i and deliveryArray %i",[queueArray count],[deliveryArray count]);
                return 50;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //Where we configure the cell in each row

    // NSString *CellIdentifier =[NSString stringWithFormat:@"%i-%i", indexPath.section,indexPath.row];
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell;

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    }
        imageViewchk1 = [[UIImageView alloc] initWithFrame:CGRectMake(56,0 , 24,24)];
        imageViewchk1.image = [UIImage imageNamed:@"check.png"];
        imageViewchk1.tag=indexPath.row+10000;
          imageViewchk1.hidden=YES;

        imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80,80)];
        imageView1.image = [UIImage imageNamed:@"newframe.png"];

        aButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [aButton1 setTag:indexPath.row];
        [aButton1 setImage:imageView1.image forState:UIControlStateNormal];
        aButton1.frame = CGRectMake(0, 0, 80,80);
        [aButton1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [aButton1 addSubview:imageViewchk1];
        [cell.contentView addSubview:aButton1];

    return cell;

       }


-(void)buttonClicked:(UIButton*)sender {
    tag = sender.tag;
    NSLog(@"buttonClicked %i",tag);

    UIImageView *imageView = (UIImageView *)[sampleTableView viewWithTag:tag+10000];


        if(imageView.hidden)
        {
            imageView.hidden=NO;
        }
        else {
            imageView.hidden=YES;

        }
    }
4

2 に答える 2

0

さて、実装の問題は、buttonClicked メソッドで imageView.hidden プロパティのみを設定することです。

セルが画面に表示されず、再び表示されると、cellForRow が再度呼び出されます。

ここでの問題は、imageView.hidden が NO に設定されているセルを保存しないことです。そのため、セルが再度表示されるたびに、cellForRow: がその imageView.hidden を YES に設定します。

したがって、解決策は、imageView.hidden= NO のセルの番号を格納し、そのインデックスパスのセルが imageView.hidden= NO のセルであるかどうかを cellForRow でチェックすることです。

于 2013-05-03T10:47:18.803 に答える