gpt4 book ai didi

objective-c - 在 iphone 的 uitablview 单元格上创建标签?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:30 24 4
gpt4 key购买 nike

我是 iPhone 开发新手,我正在开发一个应用程序。在该应用程序中,我需要在 UITableView 中显示列表项及其各自的价格。为了解决这个问题,我遵循了一些概念,比如在 UITableViewCell 中动态创建标签以显示项目及其价格。

在应用程序中,第一个 indexid == 1 意味着我在点击列表中的特定单元格时显示列表位置我正在获取最喜欢的项目列表,其价格意味着 indexid = 2 ...点击后退按钮 indexid = 1 然后我需要隐藏该标签......但标签没有隐藏它显示标价而不是项目列表

lblText.text = nil;
btnBack.hidden = FALSE;
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
cell.textLabel.highlightedTextColor = [UIColor orangeColor];

}

///////////////////// Cell Title /////////////////////
if (indexId == 1)
{
// NSLog(@"%@",lblText1);
cell.textLabel.text = [NSString stringWithFormat:@"%@", [test.arrTitle objectAtIndex:indexPath.row]];
lblText = [[UILabel alloc] initWithFrame:CGRectMake(250, 7, 40, 30)]; // For right alignment
lblText.text = [test.arrId objectAtIndex:indexPath.row];
[lblText setTextAlignment:UITextAlignmentCenter];
lblText.textColor = [UIColor redColor];
lblText.backgroundColor = [UIColor clearColor];
[cell addSubview:lblText];

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"products-category-bg.png"]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[lblText release];

}
else
{
lblText.hidden = YES;
cell.textLabel.text = [NSString stringWithFormat:@" %@", [test.arrTitle objectAtIndex:indexPath.row]];

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"product-bg-hover.png"]];
}
return cell;
}

我有以下问题。标签创建正常,但在单击后退按钮后,我在主 TableView 中获得了标签值。

如何释放带有数据的标签对象?

谢谢和问候

请帮我解决这个问题

最佳答案

我觉得你的代码没问题,只需用下面写的链接替换上面代码中的一行

[cell.contentView addSubview:lblText];

代替

[cell addSubview:lblText];

希望它能解决您的问题。

关于objective-c - 在 iphone 的 uitablview 单元格上创建标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14081446/

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