2011-06-02 59 views
0
// Customize the appearance of table view cells. 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"celluleConnecte"; 

    celluleConnecte *cell = (celluleConnecte *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     UIViewController *vue = [[UIViewController alloc] initWithNibName:@"celluleConnecte" bundle:nil]; 

     cell = (celluleConnecte *)vue.view; 
     [vue release]; 
    } 
    else { 
     asyncImageView* oldImage = (asyncImageView*) 
     [cell.contentView viewWithTag:999]; 
     [oldImage removeFromSuperview]; 
    } 


    // Configure the cell. 

    NSDictionary *dico = [self.pseudoOnline objectAtIndex:indexPath.row]; 

    cell.pseudo.text = [dico objectForKey:@"name"]; 
    cell.sexe.text = [dico objectForKey:@"sexe"]; 

    CGRect frame; 

    frame.size.width=70; frame.size.height=70; 

    frame.origin.x=5; frame.origin.y=10; 

    asyncImageView *asyncImage = [[[asyncImageView alloc] initWithFrame:frame] autorelease]; 

    asyncImage.tag =999; 


    [asyncImage loadImageFromURL:[NSURL URLWithString:[dico objectForKey:@"photo"]]]; 
    [cell.contentView addSubview:asyncImage]; 

    return cell; 

} 
+0

你的問題是什麼?您如何實現異步下載數據? – 2011-06-02 19:13:32

+0

是的。我不知道如何 – XcodeMania 2011-06-02 22:24:56

回答

1

這是因爲您在單元格中正確下載圖像,這是錯誤的。創建一個新類UIImageView並使用NSData在那裏下載照片。互聯網上有很多例子。這裏是我第一次發現markj.net/wp/wp-content/uploads/2009/02/asyncimageview.m

+0

嗨,我看到已經這個例子,但不明白..當你充滿細胞與這個cell.picture.image = [UIImage imageWithData:[NSData的dataWithContentsOfURL:[NSURL URLWithString:[dic objectForKey的:@ – XcodeMania 2011-06-02 22:25:47

+0

:@ 「url」]]]];'程序每次都下載圖片,所以這是很慢的。你必須做異步下載,並做到這一點,你必須創建一個類,它應該加載圖像,並在單元格中初始化它。 – sherilyn 2011-06-03 05:45:18

+0

現在沒事了。這很好,但還有一件事。當我向下滾動時,我可以看到圖像良好的順序,但是當我向上滾動時圖像不是很好。我需要等待1或2秒才能看到好的圖像。 – XcodeMania 2011-06-08 19:22:08