2011-05-25 78 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;   
    } 
相关问题