Ios UITableView滚动疯狂
我有一个从核心数据数组获取数据的表视图。当我尝试将对象“Post”的值分配给某个对象或NSLog时,表格滚动会滞后 这是我的密码:Ios UITableView滚动疯狂,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我有一个从核心数据数组获取数据的表视图。当我尝试将对象“Post”的值分配给某个对象或NSLog时,表格滚动会滞后 这是我的密码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellCell"; UITableViewCell *cell =
- (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
肯定会导致性能问题,特别是在频繁调用的CellForRowatineXpath
等方法中
有关详细信息,请查看以下文章:
编辑:
您的实现也会导致速度缓慢
您缺少tableviewCells的分配
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
首先,您应该添加“Midhun MP”提出的代码 如果这对滞后问题没有帮助…那么我认为post.title必须太重而不能在该方法中(因为该方法被调用太多次)(请不要让post.title使用internet连接来获取字符串?!是吗?) 解决方案:
1) 应用程序中的第一件事:创建一个array2,并将您需要的所有post.title放在其中(每次帖子更改时,您都应该更新该array2)
2) 使用此array2获取单元格的文本:cell.textLabel.textPost=[array2 objectAtIndex:indexath.row]
3) 我不能100%确定NSLog是否有问题,因为我还没有测试过(可能是…,但这应该只在调试期间发生…,在发布模式下,你不应该让它在那里),但它很容易测试和查看(只需注释NSLog行)
希望这能有所帮助。关于作业呢?为什么cell.textlab.text=post.title会使滚动延迟。使用DLOG时也会延迟。仍然没有运气。。。继续。您是否在Post对象中计算标题?