我的問題是----我在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