开发者

change a uitableviewcell subview UILabel text

This is how my tableviewcell is setup

else if(indexP开发者_Go百科ath.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];
}

I need to change the the text of the category label later on in the program. How do I accomplish this? I assume I need to use the tag to reference the UILabel?


This is how my tableviewcell is setup

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];
}

I need to change the the text of the category label later on in the program. How do I accomplish this? I assume I need to use the tag to reference the UILabel?

========================

I figured it out...

I put the UILabel in my header file and changed the code like so

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];
}

Then when I wanted to change it later I did this

categoryLabel.text = @"sample string";

And finally released it in my dealloc method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜