2014-03-06 27 views
0

我使用圖像url在UITableViewCell上設置圖像,但圖像不會得到負載,除非我滾動UITableView.Here是我一直在使用的代碼,我必須知道SDWeb圖像庫從url下載圖像,但我不想使用任何庫。請告訴我在這做什麼錯誤的目的。在iOS中設置UITableview的細胞圖像

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    // Configure the cell... 

    NSDictionary *dictCard=[cardsDetailsArray objectAtIndex:indexPath.row]; 

    UILabel *nameLabel = (UILabel *)[cell viewWithTag:10]; 
    UILabel *dateLabel = (UILabel *)[cell viewWithTag:11]; 
    UIImageView *cellImage=(UIImageView *)[cell viewWithTag:0]; 


    CGSize firstSize=CGSizeZero; 
    if([[dictCard objectForKey:@"orientation"]isEqualToString:@"1"]){ 
     [cellImage setFrame:CGRectMake(0, 0, 75, 68)]; 
     firstSize=CGSizeMake(75,68); 
    } 
    if([[dictCard objectForKey:@"orientation"]isEqualToString:@"0"]){ 
     [cellImage setFrame:CGRectMake(0, 0, 107, 72)]; 

     firstSize=CGSizeMake(107,72); 
    } 
    [cellImage setBackgroundColor:[UIColor clearColor]]; 
    NSString *string=[dictCard objectForKey:@"email_sent"]; 
    NSArray *items = [string componentsSeparatedByString:@","]; 



    dateLabel.text=[dictCard objectForKey:@"date"]; 
    nameLabel.text=[NSString stringWithFormat:@"Sent to %d People",[items count]]; 


    NSURL* url = [NSURL URLWithString:(NSString *) [dictCard objectForKey:@"card_thumbnail"]]; 
    NSURLRequest* request = [NSURLRequest requestWithURL:url]; 


    [NSURLConnection sendAsynchronousRequest:request 
             queue:[NSOperationQueue mainQueue] 
          completionHandler:^(NSURLResponse * response, 
               NSData * data, 
               NSError * error) { 
           if (!error){ 
            UIImage* image = [[UIImage alloc] initWithData:data]; 
//i am scaling the image here 
             UIImage *imageScale=[self imageWithImage:image scaledToSize:firstSize]; 
             [cellImage setImage:imageScale]; 
           } 

          }]; 




    return cell; 
} 

我還添加[__tableViewDraft reloadData];設置細胞圖像後,但由於這是我的細胞不斷改變其細胞圖像。

回答

0

一旦圖像下載完畢,您需要詢問iOS刷新單元格。退房reloadRowsAtIndexPaths:withRowAnimation:,等等。

通常,您可能已經擁有由CoreData對象支持的單元,並將該圖像下載並保存到託管對象。當託管對象更改時,您將有一個NSFetchedResultsControllerDelegate觸發更新,刷新行。

+0

可否請您在代碼中進行一些編輯以便更好地瞭解我。謝謝 – ankyy