gpt4 book ai didi

iphone - 为什么我的 UITableView 从 UITableViewStyleGrouped 更改为 UITableViewStylePlain

转载 作者:行者123 更新时间:2023-12-03 20:49:08 26 4
gpt4 key购买 nike

我的应用程序有一个扩展UITableViewController的 View Controller 。初始化方法如下所示:

- (id)initWithCoder:(NSCoder*)coder {
if (self = [super initWithCoder:coder]) {
self.tableView = [[UITableView alloc] initWithFrame:self.tableView.frame
style:UITableViewStyleGrouped];
}

return self;
}

当 View 最初加载时,它显示为UITableViewStyleGrouped。但是,如果我的应用收到内存不足警告,上述 View 将更改为 UITableViewStylePlain。没有与 View / Controller 关联的 xib 文件。 viewDidUnload 和 didReceiveMemoryWarning 方法很简单:

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

我的问题是,为什么当我收到内存警告时表格样式会发生变化?

它发生在设备和模拟器上。该设备是运行 OS 3.1.3 的 3G iphone,模拟器运行 OS 3.1

最佳答案

在初始化中,您调用 [super initWithCoder:coder] 。覆盖 UITableViewController 的指定初始化程序可能会更好。 ,即-initWithStyle: 。可能发生的情况是,当您通过调用 [super init…] 创建 TableView Controller 时,它是用 tableView 创建的属性已被设置;也就是说,它在初始化时创建 TableView 。这就是您调用 self.tableView.frame 的原因有效 - 如果 self.tableView 的值不应该有效是 nil 。这是一个更好的实现:

- (id)initWithCoder:(NSCoder*)coder {
if (self = [super initWithStyle:UITableViewStyleGrouped]) {

}

return self;
}

关于iphone - 为什么我的 UITableView 从 UITableViewStyleGrouped 更改为 UITableViewStylePlain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2639340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com