【发布时间】:2012-09-04 17:49:07
【问题描述】:
是否可以在加载视图时加载 UITableView 的所有单元格,以便在滚动时不加载它们? (我会在执行此操作时显示加载屏幕)
拜托,这是我项目中唯一的方法(抱歉太复杂了,无法解释原因^^)
编辑:
好吧,让我解释一下,我确定要做什么:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [NSString stringWithFormat:@"Identifier %i/%i", indexPath.row, indexPath.section];
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSDictionary *currentReading;
if (cell == nil)
{
cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
UILabel *label;
UIView *separator;
if(indexPath.row == 0)
{
// Here I'm creating the title bar of my "table" for each section
}
else
{
int iPr = 1;
do
{
currentReading = [listData objectAtIndex:iPr-1];
iPr++;
} while (![[currentReading valueForKey:@"DeviceNo"] isEqualToString:[devicesArr objectAtIndex:indexPath.section]] ||
[readingresultsArr containsObject:[currentReading valueForKey:@"ReadingResultId"]]);
[readingresultsArr addObject:[currentReading valueForKey:@"ReadingResultId"]];
//
// ...
//
}
}
return cell;
}
我的错误发生在 do-while-loop 中: “listData”是一个包含多个字典的数组。 我的问题是,当我慢慢向下滚动表格时,一切都很好,但是当我快速滚动到视图的末尾然后滚动到中间时,我得到了 iPr 不在的错误数组的范围。所以问题是,第一部分的最后一行已经被添加到“readingresultsArr”中,但还没有加载或想要再次加载。 这就是我想一次加载所有单元格的原因。
【问题讨论】:
-
“拜托,这是我项目中唯一的方法”——当然不应该。请解释一下,即使它很复杂。除了这不可能之外,这在内存管理方面也是一个可怕的错误。
-
@H2CO3 我已经编辑了我的问题并更详细地描述了我的问题。希望你能帮助我。
-
您能解释一下您要使用
do...while循环来完成什么吗?看起来您正试图找到一个满足某些标准的对象,然后立即构建一个新数组,但是为什么需要在那里这样做呢?您可以在重新加载表之前构建该数组吗?
标签: objective-c xcode uitableview viewdidload