0

我有一个表格视图,它从核心数据数组中获取数据。当我尝试将对象“Post”的值分配给某物或 NSLog 时,表格滚动滞后。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CellCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Post *post = [array objectAtIndex:indexPath.row];
    // If I comment out the NSLog the scroll is smoothly
    NSLog(@"%@", post.title);    
    // Same thing for the line below
    cell.textLabel.text = post.title;
    return cell;
}

编辑:

我正在使用 StackMob v1.2.0

4

2 回答 2

0

首先,您应该添加“Midhun MP”建议的代码。

如果这对滞后问题没有帮助...那么我认为 post.title 必须太重而不能使用该方法(因为该方法被调用太多次)(请不要让 post.title 使用互联网连接得到字符串?!是吗?)

解决方案:
1)在您的应用程序中的第一件事:创建一个 array2 并将您需要的所有 post.title 放入其中(每次帖子更改时,您都应该更新该 array2)
2)使用此 array2 获取单元格的文本:单元格.textLabel.textPost=[array2 objectAtIndex:indexPath.row];
3)我不能 100% 确定 NSLog 是否有问题,因为我还没有测试过(可能是……但这应该只发生在调试期间……在发布模式下你不应该在那里)但它很容易测试和查看(只需评论 NSLog 行)

希望有帮助。

于 2013-01-27T12:25:08.867 回答
0

使用NSLog肯定会导致性能问题,尤其是在cellForRowAtIndexPath频繁调用的方法中。

请查看这些文章了解详情:

  1. 在发布版本中删除 NSLog
  2. NSLog 替代品的演变

编辑 :

您的实施也会导致缓慢。

您缺少 tableviewCells 的分配。

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if(cell == nil)
 {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
 }
于 2013-01-26T09:39:20.340 回答