0

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

Superdev
  • 562
  • 7
  • 13
  • Show your code and screenshot for better understanding. – Dinesh Raja Dec 18 '13 at 13:14
  • The scroll lock can not be shown with the help of a screenshot, You can consider a situation where you are scrolling on a tableview and it stop's scrolling. – Superdev Dec 18 '13 at 13:20
  • Regarding the code i am using custom cells and adding subviews to the tableview's contentview. – Superdev Dec 18 '13 at 13:21
  • I really don't understand "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." What is that mean? could you describe the situation little bit more and show your code? – Dinesh Raja Dec 18 '13 at 13:21
  • For scrolling on a tableview we need to swipe our finger over it, Suppose i swiped my finger over a cell(any random cell) and it doesn't scroll. You are not able to identify the cell, as next time when you reload your app that cell can let you scroll. – Superdev Dec 18 '13 at 13:28

2 Answers2

0

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];
        });
    });
Nikos M.
  • 13,685
  • 4
  • 47
  • 61
0

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:.

bilobatum
  • 8,918
  • 6
  • 36
  • 50