이미지의 앞으로 버튼을 클릭하면 테이블 뷰 셀에 이미지를 표시해야하지만 스크롤 한 후에는 뷰 뷰 이미지가 변경됩니다. 셀의 각 버튼에 태그 값을 지정하고 배열의 모든 셀 참조를 저장했습니다 그리고 .. 순방향테이블 뷰 셀에 이미지 표시
을 버튼 i가 배열의 참조를 식별하고 그 특정 참조 영상을 변경하고 클릭에
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// static NSString *cellidentifier = @"cell";
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[LotsandLandTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
// cell.smallimage.image=[UIImage imageNamed:[_smallimagesarr objectAtIndex:indexPath.row]];
//if ([str_scroll isEqualToString: @"scrolling"]) {
// }else{
cell.bigimage.image=[UIImage imageNamed:[_bigimagesarr objectAtIndex:indexPath.row]];
//}
cell.forwardbutton.tag =indexPath.row;
NSLog(@" %p",cell);
[cell.forwardbutton addTarget:self action:@selector(buttonInfo:) forControlEvents:UIControlEventTouchUpInside];
CellModel *cellmodel=[[CellModel alloc]init];
cellmodel.tagValue=cell.forwardbutton.tag;
cellmodel.cellobj=cell;
[arrofcells addObject:cellmodel];
NSLog(@"%p",cell);
return cell;
}
-(void)buttonInfo:(UIButton *)sender{
UIButton *btn = (UIButton *)sender;
NSInteger tag = btn.tag;
CellModel *cmodel=[[CellModel alloc]init];
cmodel=[arrofcells objectAtIndex:tag];
democell=(LotsandLandTableCell *)cmodel.cellobj;
previoustag=cmodel.tagValue;
if(cmodel.tagValue==previoustag)
{
if(j<_bigimagesarr1.count){
democell.bigimage.image=[UIImage imageNamed:[_bigimagesarr1 objectAtIndex:j]];
NSLog(@"j value is is %d",j);
j++;
}else{
j=0;
[democell.forwardbutton setEnabled:NO];
}
}
}
cellModel 셀 참조 및 속성 태그
포함 당신이있는 tableView, 그 셀을 재사용의 더 나은 이전 셀 데이터를 지울 때 너무 이전 이미지를 사용할 수 있기 때문에있는 tableView의 이미지가 변화하고 스크롤하면
태그를 사용하지 마십시오. 왜 단순히 이미지 배열을 셀에 공급하고 셀 클래스 내의 버튼을 처리하지 않는 것이 좋을까요? 또한 셀을 다시 사용할 때마다 단추 처리기를 추가합니다. – Paulw11
@ Paulw11 님이 더 이상 할 수 없었습니다. – tnishanth
테이블보기 컨트롤러에서 버튼 탭을 처리하려고합니다. 즉, 태그를 사용하고있는 버튼 탭이 발생한 셀을 식별해야합니다. 셀은 재사용되고 재정렬 될 수 있기 때문에 태그가 깨지기 쉽습니다. 단순히 이미지 배열을 사용자 정의 셀 클래스의 속성으로 설정하면 각 셀에서 자체 단추 탭을 처리하고 해당 이미지 배열을 통해 이동할 수 있습니다. – Paulw11