【发布时间】:2012-01-05 00:08:01
【问题描述】:
我正在使用 WWDC #2010 中的 TableViewUpdates 示例。基本上,Apple 通过单击部分标题来创建可折叠和可展开的 TableView。 TableView 的数据在 viewWillAppear 中创建,如下所示:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
/*
Check whether the section info array has been created, and if so whether the section count still matches the current section count. In general, you need to keep the section info synchronized with the rows and section. If you support editing in the table view, you need to appropriately update the section info during editing operations.
*/
if ((self.sectionInfoArray == nil) || ([self.sectionInfoArray count] != [self numberOfSectionsInTableView:self.tableView])) {
// For each play, set up a corresponding SectionInfo object to contain the default height for each row.
NSMutableArray *infoArray = [[NSMutableArray alloc] init];
for (Play *play in self.plays) {
SectionInfo *sectionInfo = [[SectionInfo alloc] init];
sectionInfo.play = play;
sectionInfo.open = NO;
NSNumber *defaultRowHeight = [NSNumber numberWithInteger:DEFAULT_ROW_HEIGHT];
NSInteger countOfQuotations = [[sectionInfo.play quotations] count];
for (NSInteger i = 0; i < countOfQuotations; i++) {
[sectionInfo insertObject:defaultRowHeight inRowHeightsAtIndex:i];
}
[infoArray addObject:sectionInfo];
[sectionInfo release];
}
self.sectionInfoArray = infoArray;
[infoArray release];
}
}
我注意到我的案例中,我有大量数据,这是一项昂贵的操作。我想缓存数据。每次都会创建数据,因为它位于 viewWillAppear 中。因为我正在使用 UINavigationController 将此视图推送到堆栈上,如果我将其放入 viewDidLoad,当我离开此视图并返回家时,我必须再次重新创建视图,viewDidLoad 将再次运行,并且它会再慢一点。
我以前没有缓存过数据,想知道有什么好的方法吗?现在,行标题和行的所有数据都在数据库中。所以当这个视图被压入堆栈时,我会抓取数据并创建表。我不知道创建表并以某种方式缓存视图或其他东西以使其在 viewController 的后续推送时更快地加载的良好机制是什么。谢谢。
【问题讨论】:
标签: iphone uitableview uinavigationcontroller