objective-c - 在表格 View 单元格内的 UIImageView 中设置图像

标签 objective-c cocoa-touch ios uitableview uiimageview

我使用 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
}

最佳答案

在包含 View Controller 中

在tableView:cellForRowAtIndexPath方法下:新建cell时,添加代码:

cell.imageView.image = [UIImage imageNamed@"图片名称.png"];

关于objective-c - 在表格 View 单元格内的 UIImageView 中设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6120712/

相关文章:

ios - 使 UILabel 文本可点击

ios - 尝试更改导航 Controller 上的标题和后退按钮等属性

objective-c - 我对 'self'的理解正确吗?

ios - 带有 Xcode 6.1.1 的静态库和 cocoapods - ld : library not found Error

ios - 确定正在模拟的 iOS 设备

iphone - ios iPhone/iPad - 使用 GData 静态库 libGDataTouchStaticLib.a 的项目构建失败(重复符号)

objective-c - 无法在 UISegment 控件的段之间切换

ios - 如何在 iOS 中将 UILabel 的字体名称设置为 HelveticaNeue Thin?

ios - 将CLLocationCoordinate2D添加到自定义MKAnnotation对象

objective-c - 独立混洗两个 NSMutableArray