这是我的tableviewcell的设置方式
else if(indexPath.row == 3)
{
cell.textLabel.text = @"Category";
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = @"select a category";
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
[categoryLabel release];
}
我需要稍后在程序中更改类别标签的文本。 我该如何做到这一点?我假设我需要使用标签来引用UILabel?
答案 0 :(得分:0)
这是我的tableviewcell的设置方式
else if(indexPath.row == 3)
{
cell.textLabel.text = @"Category";
UILabel *categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = @"select a category";
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
[categoryLabel release];
}
我需要稍后在程序中更改类别标签的文本。我该如何做到这一点?我假设我需要使用标签来引用UILabel?
========================
我明白了......
我把UILabel放在我的头文件中并像这样更改了代码
else if(indexPath.row == 3)
{
cell.textLabel.text = @"Category";
categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 2, 145, 34)];
categoryLabel.adjustsFontSizeToFitWidth = YES;
categoryLabel.textColor = [UIColor blackColor];
categoryLabel.font = [UIFont systemFontOfSize:17.0];
categoryLabel.text = [NSString stringWithFormat:@"%@",categoryFriendlyString];
categoryLabel.backgroundColor = [UIColor clearColor];
categoryLabel.textAlignment = UITextAlignmentRight;
categoryLabel.tag = 3;
[cell addSubview:categoryLabel];
}
然后当我想改变它时,我做了这个
categoryLabel.text = @"sample string";
最后以我的dealloc方法发布它。