简体   繁体   English

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

[英]TableView cell stop scrolling on cell

I am trying to create feed page like Facebook, i am loading images into tableview cells using lazy loading. 我正在尝试创建类似于Facebook的供稿页面,我正在使用惰性加载将图像加载到tableview单元格中。 Sometimes a scroll lock on any random cell occurs but when i try to scroll on any other visible cell above or below, it scrolls. 有时会在任何随机单元格上发生滚动锁定,但是当我尝试在上方或下方的任何其他可见单元格上滚动时,它将滚动。 This issue is very sporadic. 这个问题非常零星。 I am not able to rectify what is causing this behaviour. 我无法纠正导致此行为的原因。 Please help. 请帮忙。

Here is the code; 这是代码;

- (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;
}

Thanks 谢谢

It looks like something is blocking your main thread (the thread responsible for the UI updates). 看起来有些东西阻塞了您的主线程(负责UI更新的线程)。 Move all the operations not related to UI updates to background queues using GCD. 使用GCD将与UI更新无关的所有操作移至后台队列。 For example: 例如:

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];
        });
    });

In tableView:cellForRowAtIndexPath:, don't remove all of the views in cell.contentView.subviews. 在tableView:cellForRowAtIndexPath:中,不要删除cell.contentView.subviews中的所有视图。 Presumably you are re-installing those views somewhere else. 大概是您在其他地方重新安装了这些视图。 This technique almost defeats the purpose of re-using table cells. 此技术几乎无法实现重用表单元格的目的。

Keep the content view's subviews in place; 保持内容视图的子视图不变; re-use them by assigning different data to them. 通过为它们分配不同的数据来重用它们。 This should improve performance. 这样可以提高性能。 If it doesn't, then post the code for renderInstagramData:cell:. 如果不是,则发布renderInstagramData:cell:的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM