UITableCell中的UIImageView在IB中显示但在模拟器中不显示?

时间:2016-04-24 06:16:43

标签: swift

我有一个奇怪的问题。所以我有一个内置UITableView / cell的UIViewController。每个单元格内都有一个UIImageView。我直接在Interface Builder上添加了图像,图像显示。

但是,当我在模拟器或iPhone上测试应用程序时,UIImageview不会出现。

很想知道你们是否有任何关于原因的想法。请查看下面的图片!

非常感谢你

(我需要10个代表才能发布图片,所以我将它们联系起来......如果那是违反规则的,我很抱歉,但我不知道如何向您展示问题!)

enter image description here enter image description here

import UIKit

class freeCell: UITableViewCell {

    @IBOutlet weak var aName: UILabel!

    @IBOutlet weak var aDescription: UILabel!

    @IBOutlet weak var aImage: UIImageView!



}

class FreeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var sharedDataApp = SharedDataApp.sharedInstanceApp

    override func viewDidLoad() {
        super.viewDidLoad()





    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)

    }

    // MARK: UITableView method implementation

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.sharedDataApp.parsedArray.count
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 100
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("freeCell", forIndexPath: indexPath) as! freeCell

    var s = self.sharedDataApp.parsedArray[indexPath.row]
    var i = s["thumbnail_url"] as! String // Prints Image URL
    cell.aName.text = s["name"] as? String
    if let imgURL = NSURL(string: "\(i)") {
        if let data = NSData(contentsOfURL: imgURL) {
            cell.aImage.image = UIImage(data: data)
            print(imgURL)

        }
    }
    //cell.aImage.image = UIImage(data: data)
    cell.aDescription.text = s["public_name"] as? String

    return cell


}

2 个答案:

答案 0 :(得分:2)

使用tableview

时执行这些操作
  1. 设置数据源并先委托
  2. 并提供合适的出路
  3. 并正确实施numberOfRowscellForRowAtIndexPath方法
  4. 并检查你的牢房高度是否合适

答案 1 :(得分:0)

我找到了原因。

这些是我采取的步骤。

  1. 打开我的项目info.plist文件添加了一个名为

  2. 的密钥
  3. NSAppTransportSecurity as a Dictionary。

  4. 添加了一个名为NSAllowsArbitraryLoads的子键作为布尔值并设置了它 值为YES,如下图所示。

相关问题