Xcode 4.3이 있고 그 클래스는 ARC를 사용하지 않습니다.스크롤 할 때 셀 데이터가 변경됩니다.
재사용 가능한 셀을 사용하는 테이블 뷰를 만들었습니다. 나는 다른 사람들에게서 해답을 얻으려고했지만 적절한 것을 얻을 수 없었다.
내 테이블은 배열에서 데이터를 가져오고 데이터를 표시하려면 UILabel
을 사용하고 이미지를 표시하려면 UIImageView
을 사용합니다.
내 코드는 다음과 같습니다. 길기는하지만 UILabel
버튼을 만들고 이미지를 한 번 변경하고 데이터를 변경하는 것이 좋습니다. 스크롤 방식
, 하나의 셀 변경 (스크롤하는 동안 다른 데이터 참조), 다른 재사용 셀은 셀 1
static NSString * CellIdentifier = @"HistoryCellId";
iImage = [UIImage imageNamed: [NSString stringWithFormat:@"%@.png",[(_searching ? _titleArrCopy : _titleArr) objectAtIndex:indexPath.row]]];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
iconImage = [[UIImageView alloc] init];
UIImage * image = [UIImage imageNamed:@"HFcellBG.png"];
UIImageView * bgImage = [[UIImageView alloc] initWithImage: image];
cell.backgroundView = bgImage;
//[iconImage removeFromSuperview];
iconImage.image = iImage;
iconImage.frame = CGRectMake(_iconX, 11, 58, 58);
//iconImage.backgroundColor = [UIColor whiteColor];
[cell addSubview:iconImage]; // show the image on the side
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleX, 3, 212, 25)];
titleLabel.textAlignment = _nibNameRTL ? UITextAlignmentRight : UITextAlignmentLeft;
[cell addSubview:titleLabel]; // show a title
timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_dateX, 25, 212, 20)];
timeLabel.textAlignment = _nibNameRTL ? UITextAlignmentRight : UITextAlignmentLeft;
timeLabel.font = [UIFont systemFontOfSize:15]; // show another data
[cell addSubview:timeLabel];
favoriteBtn = [[UIButton alloc] initWithFrame:CGRectMake(_removeX, 48, 66, 23)];
favoriteBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[favoriteBtn setTitle:getTextValue(3) forState:UIControlStateNormal];
[cell addSubview:favoriteBtn];
// show a button
}
[iconImage setImage:iImage];
[titleLabel setText:[self parserData:indexPath.row]];
[timeLabel setText:[NSString stringWithFormat:getTextValue(4),[(_searching ? _TimeArrCopy :_TimeArr) objectAtIndex:indexPath.row]]];
if ([[(_searching ? _FavoriteArrCopy : _FavoriteArr) objectAtIndex:indexPath.row] isEqualToString:@"1"]) {
[favoriteBtn setEnabled:NO];
[favoriteBtn setBackgroundImage:[UIImage imageNamed:@"HFfavoriteCheckedBtn.png"] forState:UIControlStateNormal];
}
else {
[favoriteBtn setEnabled:YES];
[favoriteBtn setBackgroundImage:[UIImage imageNamed:@"HFfavoriteBtn.png"] forState:UIControlStateNormal];
}
favoriteBtn.tag = indexPath.row;
[favoriteBtn addTarget:self action:@selector(addToFavorite:)
forControlEvents:UIControlEventTouchUpInside];
// [cell.favoriteBtn setTitle:getTextValue(3) forState:UIControlStateNormal];
// [cell.typeImage setImage:iconImage];
// cell.data = [_dataArr objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// return it
return cell;
}
데이터는 아래와 같다로부터 동일한 데이터를 표시 : 나는 5 개 세포마다 볼 수 있고 스크롤 할 때 나는 동작 아래 참조 :
1
2
3
4
5 - the cell 5 changes all the time while scrolling
1 - cell one data again
2
etc
나는 indexPath.row
을 검사 할 때, 그것이 바로 행입니다.
은 어떤 문제가 있습니까?
어떻게 해결할 수 있습니까? 하위 클래스는 어떻게 사용해야합니까? 나는 세포 nix를 원하지 않는다, 그것은 많은 문제를 만든다. –
다음 링크로 문제를 해결했습니다 : http://stackoverflow.com/questions/1802707/detecting-which-uibutton-was-pressed-in-a-uitableview –