Note that there are some explanatory texts on larger screens.

plurals
  1. POLabel refuses to disappear with [label setHidden:YES]; command in a if-method?
    text
    copied!<p>I am trying to customize my tableView in my IOS app. When my tableView(or rather array) is empty, I want to display a customized label instead of the items in the tableView. The label I am referring to is "label0". But something is terribly wrong, my [label0 setHidden:YES]; or [label0 setHidden:NO]; only works in the first block of the if "method"? In the second block (if else) nothing happens no matter what I try to set the label as (hidden or shown).</p> <p>What have I missed? I cannot see my own fault?</p> <pre><code>- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease]; UILabel *label0 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 25, tableView.bounds.size.width - 0, 100)] autorelease]; if ([self.searchResults count] == 0){ headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lista2.png"]]; UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(5, 3, tableView.bounds.size.width - 5, 18)] autorelease]; label.text = @"Information"; label.textColor = [UIColor whiteColor]; label.backgroundColor = [UIColor clearColor]; [headerView addSubview:label]; label0.text = @"Test test test"; label0.textColor = [UIColor blackColor]; label0.backgroundColor = [UIColor whiteColor]; [tableView addSubview:label0]; [label0 setHidden:NO]; } else { headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lista2.png"]]; UILabel *label2 = [[[UILabel alloc] initWithFrame:CGRectMake(5, 3, tableView.bounds.size.width - 5, 18)] autorelease]; label2.text = @"Search results"; label2.textColor = [UIColor whiteColor]; label2.backgroundColor = [UIColor clearColor]; [headerView addSubview:label2]; [label0 setHidden:YES]; } return headerView; } </code></pre> <p><strong>EDIT</strong></p> <p>I have moved the code to viewDidLoad and set the property for the UILabel. This have unfortunately not solved my problem....</p> <pre><code>UILabel *label0 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 25, tableView.bounds.size.width - 0, 100)] autorelease]; [tableView addSubview:label0]; if ([self.searchResults count] == 0){ label0.text = @"Test test test"; label0.textColor = [UIColor blackColor]; label0.backgroundColor = [UIColor whiteColor]; [label0 setHidden:NO]; } else { [label0 setHidden:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload