aur0n
aur0n

Reputation: 473

UITableView custom section header disappear

I have a view that I'm trying to use as a header section of my UITableView.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel *name= (UILabel *)[myView viewWithTag:200];
    name.text = @"title";

    myView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"row-bg-red.png"]];

    return myView;
}

It loads ok, but when I scroll down and the next header appears, the previous does the opposite: it disappears.

Any suggestion?

Upvotes: 2

Views: 2323

Answers (1)

Ondrej Peterka
Ondrej Peterka

Reputation: 3427

I guess you reuse the one view. This is not possible. Each view (UIView subclass) can be in the view hierarchy exactly once. So what probably happens in your case is that when you set the second section view, it gets removed from its original place where you put it last time for the first section.

You can create every time a new section header view directly in - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method.

Upvotes: 1

Related Questions