UITableView - Lazy Contact Image Uploads

I am working on an iPhone application that displays thumbnails from contacts in a UITableView.

Everything is very fast, until I turn on the thumbnails, then the scrolling will be very slow. All other data is supported by Core Data, and I tried to save the images in Core Data in advance, but this in itself takes too much startup time and less flexible, etc.

What I really need is a way to lazily search and sketch using a separate thread or NSOperation, etc., but I'm not sure the easiest way to accomplish this.

The apple sample of the LazyTableImages project, which is fantastic if the images come from the Internet, could certainly be adapted, although it’s hard for me to work with it. Basically the problem is the same, but instead of delaying the time from loading and network delays, etc. My delay is just the time it takes to search for images in the user's address book.

This is the task in my subclass of the table cell that I need to do at the same time:

        UIImage *contactImage = nil;
        if (ABPersonHasImageData(person)) {

        NSData *contactImageData = (NSData*)ABPersonCopyImageData(person);
        UIImage *tempContactImage = [UIImage imageWithData:contactImageData];
        [contactImageData release];

        UIGraphicsBeginImageContext(CGSizeMake(45.0f, 45.0f));             
       [tempContactImage drawInRect:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];          
       contactImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        }

Many thanks to anyone who has helpful tips or code to make this a simple and elegant way.

+3
source share
2 answers

UIImage, contactImage? tempContactImage , no?

:

cell.imageView.image = tempContactImage

EDIT:

:

ABPersonRef person = ...get person...
UITableViewCell * cell = ...get cell...
[ [ NSOperationQueue mainQueue ] addOperation:
    [ NSBlockOperation blockOperationWithBlock:^{
        if (ABPersonHasImageData(person)) {
        ...
        }
        cell.imageView.image = contactImage ;

    } ] ;

( ), , , , , .

+1

. kABPersonImageFormat * *

(NSData*)ABPersonCopyImageDataWithFormat([targetPeople objectAtIndex:index], kABPersonImageFormatThumbnail)
+1

Source: https://habr.com/ru/post/1779182/


All Articles