2011-05-25 70 views
0

這是我tableviewcell是如何設置改變一個UITableViewCell子視圖的UILabel文本

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

如果完成,請關閉該問題。 – 2011-05-25 17:03:25

+0

我該如何解決這個問題? – Hackmodford 2011-11-18 19:34:58

回答

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方法。

相關問題