UITableView滚动疯狂

我有一个从核心数据数组中获取数据的表视图。 当我尝试将对象“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

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

请查看这些文章的详细信息:

  1. 在发布版本中删除NSLog
  2. NSLogreplace的演变

编辑:

你的实现也会导致缓慢。

你错过了tableviewCells的分配。

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } 

首先你应该加上“Midhun MP”提出的代码。

如果这没有帮助滞后的问题…那么我想post.title必须是太重,不能在该方法(因为该方法被调用了太多次)(请不要让该post.title使用互联网连接得到string?!是吗?)

解:
1)在你的应用程序中的第一件事:创build一个数组2,并在那里所有你需要的post.title(每次post改变你应该更新数组2)
2)使用这个array2来获取单元格的文本:cell.textLabel.textPost = [array2 objectAtIndex:indexPath.row];
3)我不能100%确定是否NSLog是一个问题,因为我没有testing过(可能是…但这应该只发生在debugging…在释放模式,你不应该在那里),但它很容易testing,看看(只是评论NSLog线)

希望有所帮助。