- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
cell.tag = indexPath.row;
CALayer *cellImageLayer = cell.imageView.layer;
[cellImageLayer setCornerRadius:25];
[cellImageLayer setMasksToBounds:YES];
[self getImages];
[self storeImages];
UIImage *image =_ResimSonHali[indexPath.row];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(queue, ^(void) {
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
if (cell.tag == indexPath.row) {
CGSize itemSize = CGSizeMake(50, 50);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[cell setNeedsLayout];
}
});
}
});
cell.TitleLabel.text = _TarifAdi[indexPath.row];
return cell;
}
-(void)getImages
{
NSMutableArray *fuckingArrayYemek = [[NSMutableArray alloc] init];
for (int i=0; i<[_ResimAdiBase count]; i++)
{
NSString *testString=_ResimAdiBase[i];
NSArray *ImageNames = [testString componentsSeparatedByString:@"."];
[self cacheImage: _ResimAdi[i] : ImageNames[0] ];
[fuckingArrayYemek addObject:ImageNames[0]];
}
_ResimSonAdi = fuckingArrayYemek;
}
-(void) storeImages
{
NSMutableArray *fuckingArrayYemekName = [[NSMutableArray alloc] init];
for (int i=0; i<[_ResimAdiBase count]; i++)
{
[fuckingArrayYemekName addObject:[self getCachedImage:_ResimSonAdi[i]]];
}
_ResimSonHali = fuckingArrayYemekName;
}
- (void) cacheImage: (NSString *) ImageURLString : (NSString *)imageName
{
NSURL *ImageURL = [NSURL URLWithString: ImageURLString];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: imageName];
if(![[NSFileManager defaultManager] fileExistsAtPath: docFile])
{
NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL];
UIImage *image = [[UIImage alloc] initWithData: data];
if([ImageURLString rangeOfString: @".png" options: NSCaseInsensitiveSearch].location != NSNotFound)
{
[UIImagePNGRepresentation(image) writeToFile: docFile atomically: YES];
}
else if([ImageURLString rangeOfString: @".jpg" options: NSCaseInsensitiveSearch].location != NSNotFound ||
[ImageURLString rangeOfString: @".jpeg" options: NSCaseInsensitiveSearch].location != NSNotFound)
{
[UIImageJPEGRepresentation(image, 100) writeToFile: docFile atomically: YES];
}
}
}
- (UIImage *) getCachedImage : (NSString *)imageName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* cachedPath = [documentsDirectory stringByAppendingPathComponent:imageName];
UIImage *image;
if([[NSFileManager defaultManager] fileExistsAtPath: cachedPath])
{
image = [UIImage imageWithContentsOfFile: cachedPath];
}
else
{
NSLog(@"Error getting image %@", imageName);
}
return image;
}
When I load 20 data, our table does not lag behind, but when we try to increase the representation of the table of data sizes, we get a backlog from how we can prove this problem. At first we tried sending, then we tried to save the image cache, but we have a lag. Approximately we deal with this problem for about 3 days.
source
share