我的问题是----我在custom cell
中使用UITableView
当加载数据在tableview
它是加载描述和标题也日期但没有加载图像tableview.some次加载所有图像在一行。当我使用此代码滚动工作正常,但不加载图像在TableView
。我想要延迟加载概念。去下面的链接。在tableview中延迟加载图像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
newsobject=(newscustamCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (newsobject ==nil)
{
[[NSBundle mainBundle]loadNibNamed:@"newscustamCell" owner:self options:nil];
}
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(q, ^{
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[newsarry objectAtIndex:indexPath.row] objectForKey:@"image_file"]]];
/* Fetch the image from the server... */
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
/* This is the main thread again, where we set the tableView's image to
be what we just fetched. */
newsobject.allnewsimg.image = img;
// newsobject.allnewsimg.image=[UIImage imageWithData:data];
});
});
newsobject.allnewsdes.text=[[[newsarry objectAtIndex:indexPath.row] objectForKey:@"long_desc"]stringByStrippingTags];
newsobject.allnewslabel.text=[[newsarry objectAtIndex:indexPath.row] objectForKey:@"title"];
![enter image description here][1]
newsobject.timelabel.text=[[newsarry objectAtIndex:indexPath.row] objectForKey:@"date"];
return newsobject;
}
的NSData *数据= [NSData的dataWithContentsOfURL:URL];如果图像数据较大,它将阻止用户界面。它不是懒加载的概念。 – Pawan
我从URL检索480x1024大小的图像,并显示在我的tableview单元格,其中frameize只有40x40。所以我认为会的。 –
问题是关于延迟加载的概念,你可以用后台线程做同样的事情。这并不会阻止你的用户界面。 – Pawan