嗨,我在UILabel
重复相同位置时遇到问题UITableView
。
我有一个自定义单元格和三个UILabels
. 我只在 处显示第一个标签,在 处显示cellForRowAtIndexPath
另外两个didSelectRowAtIndexPath
。
当我点击单元格时,我想再显示两个标签显示,但是当我滚动 TableView 时它们在同一位置重复。
请帮我
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"English";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (isSearchOn)
{
static NSString *CellIdentifier = @"English";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *cellValue = _searchResult [indexPath.row];
cell.textLabel.text = cellValue;
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica LT Std" size:22]];
}
else
{
ConversationInEnglish *con = _conversationsInfosnew [indexPath.row];
_englishLabel = (UILabel *) [cell viewWithTag:10];
_englishLabel.text = con.english;
[_englishLabel setFont:[UIFont fontWithName:@"Helvetica LT Std" size:22]];
UIButton *starButton = [UIButton buttonWithType:UIButtonTypeCustom];
starButton.frame = CGRectMake(0 , 0 , 60, 37);
UIImage *btnImage = [UIImage imageNamed:@"star.png"];
[starButton setImage:btnImage forState:UIControlStateNormal];
starButton.tag = indexPath.row;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = starButton;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.expandedCellIndexPath isEqual:indexPath]){
}
else
{
ConversationInEnglish *con = _conversationsInfosnew [indexPath.row];
UITableViewCell *cell1 = [self.tableView cellForRowAtIndexPath:indexPath];
_myanmarLabel = (UILabel *)[cell1 viewWithTag:222];
_myanmarLabel.tag = indexPath.row;
_myanmarLabel.text = con.myanmar;
[_myanmarLabel setFont: [UIFont fontWithName:@"Masterpiece Uni Sans" size:16]];
[cell1.contentView addSubview:_myanmarLabel];
_tonebasedLabel = (UILabel *)[cell1 viewWithTag:333];
_tonebasedLabel.tag = indexPath.row;
_tonebasedLabel.text = con.tone_based;
[_tonebasedLabel setFont:[UIFont fontWithName:@"Helvetica LT Std" size:15]];
[cell1.contentView addSubview:_tonebasedLabel];
_speaker = [UIButton buttonWithType:UIButtonTypeCustom];
_speaker.frame = CGRectMake(100 , 80 , 150, 37);
UIImage *btnImage = [UIImage imageNamed:@"speaker.png"];
[_speaker setImage:btnImage forState:UIControlStateNormal];
_speaker.tag = indexPath.row;
[cell1.contentView addSubview:_speaker];
self.expandedCellIndexPath = indexPath;
self.expandedCellHeight = 110.0f;
}
[self.tableView beginUpdates];
[self.tableView endUpdates];
}