iphone - 内存警告后自定义 UITableView headerView 消失

标签 iphone cocoa-touch ios uitableview

我有一个 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。请参阅文档:

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

确认。

关于iphone - 内存警告后自定义 UITableView headerView 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4567632/

相关文章:

iphone - iPhone开发中有没有快捷方式进入/Resources/文件夹?

iphone - Interface Builder 模拟用户界面元素在景观上误导

ios - 如何在 Apple Watch 通知上设置图片?

objective-c - 为 hello world 启动什么样的项目重要吗?

ios - 访问空属性时 CoreData EXC_BAD_ACCESS (code=1, address=0x0)

iphone - Objective-C:如何覆盖/替换库中的类

ios - 交互式 View Controller 解雇和更改 statusBarStyle 不兼容?

javascript - 可以在没有 UIWebView 的情况下运行 javascript 吗?

ios - 展开 LazyVStack 显示区域

ios - 如何使用 HitTest 获得最前层而不是最深层