【发布时间】:2012-12-14 10:09:42
【问题描述】:
我是 iPhone devlopemnt 的新手,我正在开发一个应用程序。在该应用程序中,我需要在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;
}
我有以下问题。标签创建正常,但单击后退按钮后,我在主表视图中获得标签值。
如何释放带有数据的标签对象?
感谢和问候
请帮我解决这个问题
【问题讨论】:
标签: objective-c ios json