gpt4 book ai didi

ios - 在 didSelectRowAtIndexPath 创建的 UILabel 在同一位置不断重复

转载 作者:行者123 更新时间:2023-12-01 16:51:41 24 4
gpt4 key购买 nike

嗨,我对 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];
}

最佳答案

创建 UILabel 的代码似乎不在您提供的代码段中,所以我不能确定这是您的问题,但请检查您的 UILabel 框架的原点是否靠得太近。其中一个原点可能需要增加其 x 值以分隔两个 View 。

关于ios - 在 didSelectRowAtIndexPath 创建的 UILabel 在同一位置不断重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15171771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com