自定义单元格中的UIImageView中没有图像

时间:2014-05-17 02:35:48

标签: uitableview uiimageview tableview

我正在使用自定义TableCell构建TableView。并填充单元格我正在解析一些jSON。问题是我可以在两个标签中显示文本,但由于某种原因,图像没有显示在ImageView中。

我的TableCell.h类

@property (strong, nonatomic) IBOutlet UIImageView *cellImage;
@property (strong, nonatomic) IBOutlet UILabel *storePhone;
@property (strong, nonatomic) IBOutlet UILabel *storeAddress;

我的TableViewController.m类

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSDictionary *tempDictionary= [self.storeArray objectAtIndex:indexPath.row];

    cell.storePhone.text = [tempDictionary objectForKey:@"phone"];
    cell.storeAddress.text = [tempDictionary objectForKey:@"address"];

    UIImage *storeImage = [UIImage imageNamed:[tempDictionary objectForKey:@"storeLogoURL"]];
    [cell.cellImage setImage:storeImage];

    return cell;
}

我也在使用AFNetworking框架来解析jSON。

2 个答案:

答案 0 :(得分:0)

我可以使用以下代码显示图像:

NSData *imageData = [NSData dataWithContentsOfURL: [NSURL URLWithString: [tempDictionary objectForKey:@"storeLogoURL"]]];
[cell.cellImage setImage:[UIImage imageWithData: imageData]];

答案 1 :(得分:0)

快速 5 我用的是翠鸟。它是一个强大的库,用于从 Web 下载和缓存图像。您可以从 github.com/onevcat/Kingfisher 下载。 添加到 Swift Packages > Add Package Dependency

之后
import Kingfisher

class ViewController: UIViewController {
     
    @IBOutlet weak var image1: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let addURL1 = "https://it-guru.kz/img/one-service2.png"
        
        if let urlPhotos1 = URL(string: addURL1) {
            image1.kf.setImage(with: urlPhotos1, placeholder: UIImage(systemName: "folder"))
            
        }
}
相关问题