开发者

How to hide and show the label inside a table?

开发者 https://www.devze.com 2022-12-10 16:15 出处:网络
I have 3 tables called radio, song, and artist controlled by favorite. Now I want to display different text for each table when there is nothing inside the table. But I want the text to be removed whe

I have 3 tables called radio, song, and artist controlled by favorite. Now I want to display different text for each table when there is nothing inside the table. But I want the text to be removed when there is something inside the table. I could display the text, by adding label into it.

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

but after the text is hidden in one table ( meaning there is something added only to that particular table) but the other texts in other tables also disappeared.

- (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.
        开发者_如何学Go[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];       
    }

this is the code where I remove the things for the webradio table. ( the other 3 tables also the same) I appriciate if anyone could help me in this problem I've been having.


If you are reusing the table cells across tables, then this might help:

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


I removed the if else statement and it worked fine.

0

精彩评论

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