Loading image from CoreData at cellForRowAtIndexPath slows down scrolling

后端 未结 3 764
面向向阳花
面向向阳花 2020-12-01 07:08

I am working on a UITableView that is very much like the iOS\'s native Photo app: it has many rows with 4 image thumbnails in each row. (i.e. each UITableViewCell has 4 UIIm

3条回答
  •  日久生厌
    2020-12-01 07:27

    Add a subClass of NSValueTransformer for image in core data,

    Code like follows:

    + (BOOL)allowsReverseTransformation {
        return YES;
    }
    + (Class)transformedValueClass {
        return [NSData class];
    }
     - (id)transformedValue:(id)value {
        return UIImageJPEGRepresentation(value, 0.5);
     }
    - (id)reverseTransformedValue:(id)value {
        return [[UIImage alloc] initWithData:value];
    } 
    

提交回复
热议问题