【问题标题】:How to hide and show the label inside a table?如何隐藏和显示表格内的标签?
【发布时间】:2009-11-04 05:09:41
【问题描述】:

我有 3 个表,分别由收藏夹控制,分别称为收音机、歌曲和艺术家。 现在,当表格内没有任何内容时,我想为每个表格显示不同的文本。但是我希望在表格中有内容时删除文本。我可以通过在其中添加标签来显示文本。

if ([mainDataCenter.favoriteArtistArray count] == 0)
    {
        [label setTextColor:[UIColor whiteColor]];
        [label setText:@"AUCUN FAVORI DE FICHE ARTISTE"];
    }
    else
    {
        [label setHidden:YES];
    }

但是在文本被隐藏在一个表中之后(意味着仅在该特定表中添加了一些内容),但其他表中的其他文本也消失了。

- (void)tableView:(UITableView*)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath*)indexPath 
{
    // If row is deleted, remove it from the list.
    if (UITableViewCellEditingStyleDelete == editingStyle) 
    {
        WebRadio *aRadio = [mainDataCenter.favoriteWebRadioArray objectAtIndex:indexPath.row];
        [mainDataCenter removeWebRadioFromFavorite:aRadio];
        // Animate the deletion from the table.
        [tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];       
    }

这是我删除 webradio 表内容的代码。 (其他3张桌子也一样) 如果有人可以帮助我解决我遇到的这个问题,我很感激。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview


    【解决方案1】:

    如果您跨表格重复使用表格单元格,那么这可能会有所帮助:

    if ([mainDataCenter.favoriteArtistArray count] == 0)
    {
        [label setHidden:NO]; // show label if it was hidden
        [label setTextColor:[UIColor whiteColor]];
        [label setText:@"AUCUN FAVORI DE FICHE ARTISTE"];
    }
    else
    {
        [label setHidden:YES];
    }
    

    【讨论】:

      【解决方案2】:

      我删除了 if else 语句,它运行良好。

      【讨论】:

        猜你喜欢
        • 2016-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多