UICollectionView scrolling is slow

后端 未结 3 1784
北恋
北恋 2020-12-25 08:43

I have just created a UICollectionView in which The user can add images from their phone to the photo album feature in the app. I have the images save to the a

3条回答
  •  难免孤独
    2020-12-25 09:23

    You will need to make a approach like the one you need to do in the tableviews, you will need to reuse the views, like you reuse yours cells in table view.

    A really good tutorial is this one from Ray Wenderlich:

    In the first part you have the basic, in the second one they talk about the reusable views, you, take a look at the link:

    http://www.raywenderlich.com/22417/beginning-uicollectionview-in-ios-6-part-22

    Edit

    Example to load images async:

    Create at your cell a method loadImageFromFile for example, that receives the path you will cal it this way:

    [cell loadImageFromFile:[recipePhotos objectAtIndex:index]];
    

    And then will look like (maybe you need to adapt something ...):

    - (void) loadImageFromFile:(NSString*)path{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{
            NSData *data= [NSData dataWithContentsOfFile:path];
            UIImage *theImage=[UIImage imageWithData:data];
    
            dispatch_async(dispatch_get_main_queue(), ^{
                cell.imageView.image=theImage;
        });
    });
    

提交回复
热议问题