细胞subviews消失,而滚动的uitableview
问题描述:
我正在做下面的代码。问题是,当我在滚动一个单元将会无形部分,当我们再次来到可见部分细胞的子视图都走了样标签等细胞subviews消失,而滚动的uitableview
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"playcell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
}
if (indexPath.section == 0) {
if (indexPath.row == 0) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"header.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}else if (indexPath.row == self.yourTurnPlayList.count +1) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"footer.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}
else {
int pathValue = indexPath.row -1 ;
if (pathValue > (-1) && pathValue < self.yourTurnPlayList.count) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateNormal];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateHighlighted];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateSelected];
GamePlay *gamePlay = [self.yourTurnPlayList objectAtIndex:pathValue];
cell.backgroundCellBtn.tag = pathValue;
cell.nameTextLbl.text = [self getCurrentPlayerFormattedName:gamePlay];
cell.playtimeLbl.text = [NSString stringWithFormat:@"played %@",[Helper getLastPlayedStringFromUnixTime:gamePlay.lastMoveTime]];
}
}
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"header2"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}else if (indexPath.row == self.theirTurnPlayList.count +1) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"footer2.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}
else {
int pathValue = indexPath.row -1 ;
if (pathValue > (-1) && pathValue < self.theirTurnPlayList.count) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateNormal];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateHighlighted];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateSelected];
cell.backgroundCellBtn.userInteractionEnabled = NO;
GamePlay *gamePlay = [self.theirTurnPlayList objectAtIndex:pathValue];
cell.nameTextLbl.text = [self getCurrentPlayerFormattedName:gamePlay];
cell.playtimeLbl.text = [NSString stringWithFormat:@"%@",[Helper getLastPlayedStringFromUnixTime:gamePlay.lastMoveTime]];
}
}
}
return cell;
}
答
由于电池是由你隐藏。当他们重新使用,他们是隐藏的,所以你sholud设置隐藏是NO,重复使用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"playcell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
}
if (indexPath.section == 0) {
if (indexPath.row == 0) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"header.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}else if (indexPath.row == self.yourTurnPlayList.count +1) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"footer.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}
else {
int pathValue = indexPath.row -1 ;
if (pathValue > (-1) && pathValue < self.yourTurnPlayList.count) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateNormal];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateHighlighted];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateSelected];
GamePlay *gamePlay = [self.yourTurnPlayList objectAtIndex:pathValue];
cell.backgroundCellBtn.tag = pathValue;
cell.nameTextLbl.text = [self getCurrentPlayerFormattedName:gamePlay];
cell.playtimeLbl.text = [NSString stringWithFormat:@"Last played %@",[Helper getLastPlayedStringFromUnixTime:gamePlay.lastMoveTime]];
//add these
cell.nameTextLbl.hidden = NO;
cell.playtimeLbl.hidden = NO;
cell.lineSperatorImageView.hidden = NO;
}
}
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"header2"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}else if (indexPath.row == self.theirTurnPlayList.count +1) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"footer2.png"] forState:UIControlStateNormal];
cell.backgroundCellBtn.userInteractionEnabled = NO;
cell.nameTextLbl.hidden = YES;
cell.playtimeLbl.hidden = YES;
cell.lineSperatorImageView.hidden = YES;
}
else {
int pathValue = indexPath.row -1 ;
if (pathValue > (-1) && pathValue < self.theirTurnPlayList.count) {
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateNormal];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateHighlighted];
[cell.backgroundCellBtn setBackgroundImage:[UIImage imageNamed:@"sample.png"] forState:UIControlStateSelected];
cell.backgroundCellBtn.userInteractionEnabled = NO;
GamePlay *gamePlay = [self.theirTurnPlayList objectAtIndex:pathValue];
cell.nameTextLbl.text = [self getCurrentPlayerFormattedName:gamePlay];
cell.playtimeLbl.text = [NSString stringWithFormat:@"%@",[Helper getLastPlayedStringFromUnixTime:gamePlay.lastMoveTime]];
//add these
cell.nameTextLbl.hidden = NO;
cell.playtimeLbl.hidden = NO;
cell.lineSperatorImageView.hidden = NO;
}
}
}
return cell;
}
+0
细胞没有隐藏我躲在细胞标签的第一个和最后一个..我认为得到它...试试 – 2013-02-27 04:21:54
+0
感谢它的工作..这是愚蠢的错误:( – 2013-02-27 04:33:49
时,每个单元有代码相同的设计?,否则使用不同的CellIdentifier对不同势细胞 – NANNAV 2013-02-27 04:05:01