TableView单元格停止在单元格上滚动

时间:2013-12-18 13:04:29

标签: ios uitableview tableviewcell scroll-lock

我正在尝试像Facebook一样创建供稿页面,我正在使用延迟加载将图像加载到tableview单元格中。有时会出现任何随机单元格的滚动锁定,但是当我尝试滚动上方或下方的任何其他可见单元格时,它会滚动。这个问题非常零星。我无法纠正导致此行为的原因。请帮忙。

这是代码;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //label to show values of the menu
    static NSString *CellIdentifier = @"CellIdentifier";

    // Dequeue or create a cell of the appropriate type.
    socialFeedCustomCell *cell = (socialFeedCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[socialFeedCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    for (UIView *tempView in cell.contentView.subviews) {
        [tempView removeFromSuperview];
    }

        [self renderInstagramData:indexPath cell:cell];

    cell.contentView.layer.opaque=YES;
    cell.layer.shouldRasterize = YES;
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor clearColor];
    cell.userInteractionEnabled=YES;

    return cell;
}

由于

2 个答案:

答案 0 :(得分:0)

看起来有些东西阻塞了你的主线程(负责UI更新的线程)。使用GCD将与UI更新无关的所有操作移动到后台队列。例如:

dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);

    // execute a task on that queue asynchronously
    dispatch_async(jsonParsingQueue, ^{
     // Parse your data here

        dispatch_async(dispatch_get_main_queue(), ^{
           // Update your UI in the main thread
           [self.tableView reloadData];
        });
    });

答案 1 :(得分:0)

在tableView:cellForRowAtIndexPath:中,不要删除cell.contentView.subviews中的所有视图。据推测,您正在其他地方重新安装这些视图。这种技术几乎无法重复使用表格单元格。

保留内容视图的子视图;通过为它们分配不同的数据来重用它们。这应该可以提高性能。如果没有,则发布renderInstagramData:cell:。

的代码
相关问题