简体   繁体   中英

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. 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). Move all the operations not related to UI updates to background queues using GCD. 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. 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:.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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