Alex Rivera | Logout

Custom UITableView headerView disappears after memory warning

Asked 2010-12-31T02:09:13.090
15

I have a UITableViewController. I create a custom headerView for it's tableView in the loadView method like so:

(void)loadView {
    [super loadView];

    UIView* containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height * 2 )];  
    containerView.tag = 'cont';
    containerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;

    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(padding, height, width, height);
    ... //configure UIButton and events

    UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"] highlightedImage:[UIImage imageNamed:@"highlight.png"]];    
    imageView.frame = CGRectMake(0, 0, width, height );
    ... //configure UIImageView

    [containerView addSubview:button];
    [containerView addSubview:imageView];
    self.tableView.tableHeaderView = containerView;

    [imageView release];
    [containerView release];
}

None of the other methods (viewDidLoad/Unload, etc) are overloaded.

This controller is hosted in a tab. When I switch to another tab and simulate a memory warning, and then come back to this tab, my UITableView is missing my custon header. All the rows/section are visible as I would expect. Putting a BP in the loadView code above, I see it being invoked when I switch back to the tab after the memory warning, and yet I can't actually see the header.

Any ideas about what I'm missing here?

EDIT: This happens on the device and the simulator. On the device, I just let a memory warning occur by opening a bunch of different apps while mine is in the background.

Edit
Report

2 Answers

6

the loadView method shouldn't call super. Try removing [super loadView]; and that may well solve your problem. The other overridden view methods (viewDidLoad, viewWillAppear etc.) can call super just fine. See the documentation at:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

for confirmation.

answered 2011-01-08T13:05:56.877
-2

This problem is known. For example, if you use the TableViewDelegate tableView:viewForHeaderInSection: it won't work, too.

The problem is iOS and not you. There aren't many questions about the tableHeaderView because nobody use it, and so Apple didn't get any BugTracker entries...

Have a look to a older question: here. And here are other problems.

So I think really it's a SDK bug...

answered 2011-01-08T11:17:32.640

Your Answer