【发布时间】:2013-12-06 06:27:31
【问题描述】:
我有一个动态表格视图,其中一个单元格被选中,并在其下方显示另一个包含UIDatePicker 的单元格 - 就像在日历应用程序中一样。
这很好用,但是当用户第一次滚动到单元格时(当它的高度为 0 时),我在单元格的初始加载时遇到了问题。
调查为什么它很慢,我将 dequeueReusableCellWithIdentifier 调用封装在 NSLogs 中以查看时间。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [[cellIdentifiers objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
NSLog(@"Creating cell:%@", CellIdentifier);
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSLog(@"Finished cell:%@", CellIdentifier);
return cell;
}
NSLog 显示:
14:47:42.427 Creating cell:Date
14:47:42.437 Finished cell:Date
14:47:42.470 Creating cell:DatePicker
14:47:43.006 Finished cell:DatePicker
14:47:43.046 Creating cell:Time
14:47:43.055 Finished cell:Time
14:47:44.753 Creating cell:DatePicker
14:47:45.253 Finished cell:DatePicker
日期/时间是包含 2 个 UILabel 的单元格,而 DatePicker 是包含一个 UIDatePicker 的单元格。
UIDatePicker 单元大约需要半秒才能完成。第一次滚动后,它的加载速度要快得多,因此没有明显的延迟 - 除了第一次点击日期单元格时,它下方的 DatePicker 单元格将其高度从 0 更改为 220。
首次打开单元格的NSLog:
14:59:34.334 Creating cell:DatePicker
14:59:34.877 Finished cell:DatePicker
我注意到日历应用在第一次打开 UIDatePicker 单元格时有轻微的延迟,但这似乎不像我的应用那样长。
我正在 iPhone 4 上进行测试,这可能是一个促成因素。
有没有人知道我可能做错了什么或可以做些什么来加快速度?
【问题讨论】:
-
这就是 Instruments 的用途。使用时间分析器,看看它花了这么长时间。
标签: ios uitableview uidatepicker