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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With