我正在使用GCD異步加載我的uitableview的圖像,但存在一個問題 - 向下滾動時,UITableview圖像消失在頂部。有時圖像不顯示在UITableViewCell中。這是我的code.please給我任何想法。我的code.Is有任何錯誤,請幫助我。如何使用異步GCD加載圖像對於UITableviewcell/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"];
}
image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 80)];
[cell.contentView addSubview:image];
str=att.classimage;
[email protected]"My URL";
if(str!=nil){
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *imageStr=[url stringByAppendingString:str];
image.image = [UIImage imageNamed:imageStr];
});
});
image.image=[UIImage imageNamed:@"nav-bar-logo.png"];
}
return cell;
}
您正在使用中退出的小區標識爲@ 「細胞」 和標識,而分配/ INITING細胞是@ 「標識」。 – chandu
並修復瞭如何添加imageView。目前它總是添加,而cellForRow被稱爲 – Joshua
我想建議你緩存圖像,如果圖像來自服務器。 – Leena