Hy, ребята, у меня проблема, у меня есть таблица с 4 изображениями в каждой ячейке, мне нужно знать, какое изображение было нажато, поэтому я помещаю изображения на кнопку
Все работает хорошо, но при этомпрокрутка, а не сбой, просто застрял, чтобы подумать секунду, а затем прокрутите снова.Может кто-нибудь помочь?вот код:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *b1, *b2, *b3, *b4;
UIImageView *lBut1,*lBut2,*lBut3,*lBut4;
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
b1 = [UIButton buttonWithType:UIButtonTypeCustom];
b1.frame = CGRectMake(y, y, x, x);
UIImage* img = [UIImage imageWithContentsOfFile:[dataArray objectAtIndex:indexPath.row*4]];
[b1 setBackgroundImage:img forState:UIControlStateNormal];
b1.tag = indexPath.row*4+1;
[b1 addTarget:self action:@selector(reportChoose:) forControlEvents:UIControlEventTouchUpInside];
lBut1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
lBut1.frame = CGRectMake(0, 0, x, x);
[lBut1 setAlpha:0.5];
[b1 addSubview:lBut1];
[lBut1 release];
[cell addSubview:b1];
if (indexPath.row * 4 + 1 < [dataArray count]) {
b2 = [UIButton buttonWithType:UIButtonTypeCustom];
b2.frame = CGRectMake(2*y+x, y, x, x);
UIImage* img = [UIImage imageWithContentsOfFile:[dataArray objectAtIndex:indexPath.row*4 + 1]];
[b2 setBackgroundImage:img forState:UIControlStateNormal];
b2.tag = indexPath.row*4+2;
[b2 addTarget:self action:@selector(reportChoose:) forControlEvents:UIControlEventTouchUpInside];
lBut2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
lBut2.frame = CGRectMake(0, 0, x, x);
[lBut2 setAlpha:0.5];
[b2 addSubview:lBut2];
[lBut2 release];
[cell addSubview:b2];
}
if (indexPath.row * 4 + 2 < [dataArray count]) {
b3 = [UIButton buttonWithType:UIButtonTypeCustom];
b3.frame = CGRectMake(3*y+2*x, y, x, x);
UIImage* img = [UIImage imageWithContentsOfFile:[dataArray objectAtIndex:indexPath.row*4 + 2]];
[b3 setBackgroundImage:img forState:UIControlStateNormal];
b3.tag = indexPath.row*4+3;
[b3 addTarget:self action:@selector(reportChoose:) forControlEvents:UIControlEventTouchUpInside];
lBut3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Defaulte.png"]];
lBut3.frame = CGRectMake(0, 0, x, x);
[lBut3 setAlpha:0.5];
[b3 addSubview:lBut3];
[lBut3 release];
[cell addSubview:b3];
}
if (indexPath.row * 4 + 3 < [dataArray count]) {
b4 = [UIButton buttonWithType:UIButtonTypeCustom];
b4.frame = CGRectMake(4*y+3*x, y, x, x);
UIImage* img =[UIImage imageWithContentsOfFile:[dataArray objectAtIndex:indexPath.row*4 + 3]];
[b4 setBackgroundImage:img forState:UIControlStateNormal];
b4.tag = indexPath.row*4+4;
[b4 addTarget:self action:@selector(reportChoose:) forControlEvents:UIControlEventTouchUpInside];
lBut4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Defaulte.png"]];
lBut4.frame = CGRectMake(0, 0, x, x);
[lBut4 setAlpha:0.5];
[b4 addSubview:lBut4];
[lBut4 release];
[cell addSubview:b4];
}
return cell;
}