如何解决更改uitableviewcell子视图UILabel文本
| 这是我的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?
解决方法
这是我的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,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方法中发布了它。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。