检查滚动后删除的图像。
我必须重用单元格,也不想使用didselectrow方法,因为我在一个单元格中有多个按钮,这是我为 stackoverflow 创建的示例。
我在谷歌搜索了很多,发现无能为力。
这是我的示例代码
//
// 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;
}
}