添加大图像或内容时,表格视图滚动不平滑

时间:2014-03-31 12:52:52

标签: ios afnetworking xib

我正在使用表格视图来显示数据列表。每个自定义表格单元格都有一个来自 JSON 的背景图像。我使用 AFNetworking 框架下载这些图片。 但是表格视图滚动不顺畅。我使用.xib文件创建这些单元格。

static  NSString *CellIdentifire=@"CellId";
NSMutableDictionary *murDic=[matchListarry objectAtIndex:indexPath.row];
TTTCellFormatchList *matchListcell;
matchListcell=(TTTCellFormatchList *)[tableView dequeueReusableCellWithIdentifier:CellIdentifire];
if (matchListcell==nil)
{          
  NSArray *CellNib=[[NSBundle mainBundle] loadNibNamed:@"TTTCellFormatchListcontroller" owner:self options:nil];
  matchListcell=(TTTCellFormatchList *)[CellNib objectAtIndex:0];
}
UIView *MainView=(UIView *)[matchListcell.contentView viewWithTag:101];
UIActivityIndicatorView *Spinner=(UIActivityIndicatorView *)[MainView viewWithTag:93];
//Clearing The back Ground
matchListcell.backgroundColor=[UIColor clearColor];
//Downlod back ground image in block and background thread

NSString *BackgroundImageStgring=[murDic valueForKey:@"MatchImage"];    
UIImageView *BackgrounImage=(UIImageView *)[matchListcell.contentView viewWithTag:100];
NSURLRequest *request_img = [NSURLRequest requestWithURL:[NSURL URLWithString:BackgroundImageStgring]];    
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request_img, imageProcessingBlock:nil, success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) 
{
  if(image!=nil)
  {
    image=[image blurredImageWithRadius:2 iterations:1 tintColor:[UIColor darkGrayColor]];
    [BackgrounImage setImage:image];
    [Spinner stopAnimating];
    [Spinner setHidden:YES];                                                                                               
  }
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[[UIImage imageNamed:@"picture.png"] applyLightEffect];
[BackgrounImage setImage:[UIImage imageNamed:@"picture.png"]];
NSLog(@"Error %@",error);
}];
[operation start];

1 个答案:

答案 0 :(得分:0)

//调用后台队列以动态加载数据

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

// load your dynamic data here

// call main queue here
dispatch_async(dispatch_get_main_queue(), ^{
 // after loading data in background. use your downloaded data here.  
});
});

Custom UITableView with UITextview is not scrolling smoothly in ios device