当我将数据直接映射到集合视图项时,我在滚动时遇到问题意味着它在滚动时会挂起。是否有解决此问题的方法
我的代码在
之下- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Configure the cell
static NSString *identifier = @"Cell";
NSMutableArray *image_arr;
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UILabel *title_lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 190, 145, 20)];
if (boolsearch==YES)
{
self.scrollView.scrollsToTop=YES;
title_lbl.backgroundColor=[UIColor colorWithRed:0.752 green:0.752 blue:0.752 alpha:0.75];
title_lbl.text=[[arr_search_Lbl objectAtIndex:0] objectAtIndex:indexPath.row];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[arr_search valueForKey:@"movie_image"] objectAtIndex:indexPath.row]]]]];
// [cell addSubview:cellImage];
dispatch_queue_t myqueue = dispatch_queue_create("myqueue", NULL);
// execute a task on that queue asynchronously
dispatch_async(myqueue, ^{
NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@",[[arr_search valueForKey:@"movie_image"] objectAtIndex:indexPath.row]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];;
NSData *data = [NSData dataWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage*img = [UIImage imageWithData:data];
NSArray *imgesArrayBeforeSearching=[NSArray arrayWithObjects:img, nil];
NSLog(@" arry count for images from url %@",imgesArrayBeforeSearching );
//UI updates should be done on the main thread
});
});
NSString *mediaURl=[[image_arr objectAtIndex:0]objectAtIndex:indexPath.row];
NSLog(@" media thumb nil url is %@",mediaURl);
//cell.backgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tentkotta_logo.png"]];
cell.backgroundView.frame=CGRectMake(10, cell.backgroundView.frame.origin.y, cell.backgroundView.frame.size.width, cell.backgroundView.frame.size.height);
[cell addSubview:title_lbl];
}
else
{
Media *media = [self.mediaList mediaAtIndex:(int)indexPath.row];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[SimpleImageFetcher getDataFromImageURL:media.thumbnailURL]]];
dispatch_queue_t myqueue = dispatch_queue_create("myqueue", NULL);
// execute a task on that queue asynchronously
dispatch_async(myqueue, ^{
NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@",media.thumbnailURL] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];;
NSData *data = [NSData dataWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage*img = [UIImage imageWithData:data];
NSArray *imgesArrayBeforeSearching=[NSArray arrayWithObjects:img, nil];
NSLog(@" arry count for images from url %@",imgesArrayBeforeSearching );
//UI updates should be done on the main thread
});
});
NSLog(@" ******************** media title is ******* %@",media.title);
title_lbl.backgroundColor=[UIColor colorWithRed:0.752 green:0.752 blue:0.752 alpha:0.75];
title_lbl.text=media.title;
[cell addSubview:title_lbl];
}
return cell;
}