gpt4 book ai didi

iphone - 更新后,UI 标签值在 TableView 中重叠

转载 作者:行者123 更新时间:2023-12-03 20:14:15 24 4
gpt4 key购买 nike

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSString *CellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.row];

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//clear all the cells subview before drawing the cell
for(UIView *view in cell.contentView.subviews)
{
if ([view isKindOfClass:[UIView class]])
{
[view removeFromSuperview];
}
}

if (arrPlaceId.count>0)
{


lblPlacename=[[UILabel alloc]initWithFrame:CGRectMake(30, 3, 300, 20)];
lblPlacename.font=[UIFont fontWithName:@"arial" size:15];
lblPlacename.textColor=[UIColor whiteColor];

lblPlacename.backgroundColor=[UIColor clearColor];

lblAddress=[[UILabel alloc]initWithFrame:CGRectMake(30, 20, 300, 18)];
lblAddress.font=[UIFont fontWithName:@"arial" size:15];
lblAddress.textColor=[UIColor whiteColor];

lblAddress.backgroundColor=[UIColor clearColor];


lblPlacename.text=[arrPlaceName objectAtIndex:indexPath.row];
lblAddress.text=[arrPlaceAddress objectAtIndex:indexPath.row];


[cell addSubview:lblPlacename];
[cell addSubview:lblAddress];
}



return cell;
}

最佳答案

将此添加到您的方法

for(id obj in cell.contentView.subviews)
{
if([obj isKindOfClass:[UILabel class]])
{
[obj removeFromSuperview];
}
}

而不是

for(UIView *view in cell.contentView.subviews)
{
if ([view isKindOfClass:[UIView class]])
{
[view removeFromSuperview];
}
}

关于iphone - 更新后,UI 标签值在 TableView 中重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19219973/

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