2011-05-25 35 views
0

我使用NSThread下載了一些圖像。當所有的圖像下載後,我必須把它們放在cell.myimageview中。給我提供用戶定義方法設置圖像的解決方案。如何在適合視圖中設置圖像

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


     static NSString *CellIdentifier = @"Cell"; 
     TableCell *cell = (TableCell *)[TableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (cell == nil) { 

      cell = [[[TableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

     } 


     NSString *bedsbaths=[NSString stringWithFormat:@"Beds:%@ Baths:%@",[[AppDeleget.statuses valueForKey:@"beds"] objectAtIndex:indexPath.row],[[AppDeleget.statuses valueForKey:@"baths"] objectAtIndex:indexPath.row]]; 
     cell.mlsno.text=[[AppDeleget.statuses valueForKey:@"mlsno"] objectAtIndex:indexPath.row]; 
     cell.price.text=[[AppDeleget.statuses valueForKey:@"price"] objectAtIndex:indexPath.row]; 
     cell.address.text=[[AppDeleget.statuses valueForKey:@"address"] objectAtIndex:indexPath.row]; 
     cell.bedsbaths.text=bedsbaths; 
     cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; 
    return cell; 

    } 
    -(void)LoadImage 
    { 
     for(int x=0;x<[ListPhotos count];x++) 
     { 
      NSData *imageData =[ListPhotos objectAtIndex:x]; 
      id path = imageData; 
      NSURL *url = [NSURL URLWithString:path]; 
      NSLog(@"%@",url); 
      NSData *data = [NSData dataWithContentsOfURL:url]; 
      UIImage *img = [[UIImage alloc] initWithData:data]; 
      [self performSelectorOnMainThread:@selector(downloadDone:) withObject:img waitUntilDone:NO]; 
     } 

    } 
    -(void)downloadDone:(UIImage*)img { 

     // I have to set the cell here. How?   
     cell.myimageView.image=img 
    } 
+0

是否'ListPhotos'包含表視圖 – visakh7 2011-05-25 09:45:08

+0

相同數量的對象作爲行數的我解決方案工作如果沒有,infrm me.elase接受答案 – KingofBliss 2011-05-25 10:54:28

回答

0

-(void)LoadImage

存放在NSArray中的IMG。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,代碼

cell.myimageView.image=[imgArray objectAtIndex:indexPath.row]; 

指定的代表和實現代碼如下作爲數據源,

-(void)downloadDone:(UIImage*)img { 
     self.tableView.delegate=self;  
     self.tableView.datasource=self;   
    } 
相關問題