0

I have a question about table view cells.

In cell I have an UIImageView. This view loads from web service with getter:

- (UIImageView *)imageView
{
    if (!_ imageView)
    {
        _imageView = [[TurnipImageView alloc] init];

        _imageView.backgroundColor = [UIColor clearColor];
    }

    [_imageView loadImageViewFromWebService];

    return _imageView;
}

When I add [_imageView loadImageViewFromWebService]; call inside of if (!_ imageView) statement, image view is not loaded correctly.

When I scroll table view, cells are reloading as well as image views and causing lags in scrolling.

Maybe anyone knows how to optimise this process?

2 Answers2

0

You should try lazy loading of the table view : here is the sample : https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html

also have a look at this : Lazy loading UITableView with multiple images in each cell

Community
  • 1
  • 1
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
0

Try this

dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
    //perform download on background thread
    dispatch_async(dispatch_get_main_queue(), ^{
       //assign image to imageview on main thread, UI operations should be carried on main thread
    });
});



- (UIImageView *)imageView
{
    if (!_ imageView)
    {
        _imageView = [[TurnipImageView alloc] init];

        _imageView.backgroundColor = [UIColor clearColor];
    }
    dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
    //perform download on background thread

        [_imageView loadImageViewFromWebService];
    });
    return _imageView;
}

Hope this helps

Saif
  • 2,678
  • 2
  • 22
  • 38