我有一个 UITableView,它在 200 个部分中有大约 400 个单元格,它在响应用户交互(滚动、选择单元格)方面有点迟缓。我确保检索单元格和标题视图的方法在运行时做到了最低限度,并且我不认为我正在做任何不寻常的事情来让它变慢。单元格和标题只有背景图像和文本。有没有其他人遇到过这种问题,你知道有什么方法可以让它运行得更快一点吗?
编辑:我提供赏金,因为我很想得到一些有用的反馈。我认为答案不在于我的代码中的问题。相反,我正在寻找重新设计 UITableView 以使其运行得更快的策略。我完全愿意添加新代码,我期待听到你们的意见。
在模拟器和我的设备 iPhone 4 上都观察到了迟缓。这是我的viewForHeaderInSection
和的实现cellForRowAtIndexPath
,它们是唯一UITableViewDelegate
不平凡地实现的方法。我正在重用单元格和标题视图。
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
{
HaikuHeaderView* view= [m_sectionViews objectAtIndex:section];
NSMutableArray* array= [m_haikuSearch objectAtIndex:section];
Haiku* haiku= [array objectAtIndex:0];
[view.poetLabel setText:[haiku nameForDisplay]];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.backgroundView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell gradient2.png"]];
// (Set up a bunch of label attributes in the cell...)
}
NSMutableArray* array= [m_haikuSearch objectAtIndex:indexPath.section];
Haiku* haiku = [array objectAtIndex:indexPath.row];
cell.textLabel.text = [haiku.m_lines objectAtIndex:0];
return cell;
}