我有一个 UITableViewController
。我在 loadView
方法中为其 tableView
创建了一个自定义 headerView,如下所示:
(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];
}
没有重载其他方法(viewDidLoad/Unload 等)。
此 Controller 托管在选项卡中。当我切换到另一个选项卡并模拟内存警告,然后返回到此选项卡时,我的 UITableView
缺少我的自定义 header 。如我所料,所有行/部分都是可见的。在上面的 loadView
代码中放置一个 BP,当我在内存警告后切换回选项卡时,我看到它被调用,但我实际上看不到标题。
关于我在这里缺少的东西有什么想法吗?
编辑:这发生在设备和模拟器上。在设备上,当我的设备处于后台时,我只是通过打开一堆不同的应用程序来发出内存警告。
最佳答案
loadView 方法不应调用 super。尝试删除 [super loadView];这很可能会解决您的问题。其他重写的 View 方法(viewDidLoad、viewWillAppear 等)可以很好地调用 super。请参阅文档:
确认。
关于iphone - 内存警告后自定义 UITableView headerView 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4567632/