brkr
brkr

Reputation: 1272

UIImageView in UITableCell shows in IB but not in Simulator?

I have a weird problem. So I have a UIViewController with a UITableView/cell inside. Within each cell is a UIImageView. I'v added the image directly on the Interface Builder and the image shows.

But, when I test the app live on the simulator or my iPhone the UIImageview does not appear.

Would love to see if any of you have ideas on why. Please check out images below!

Thank you all very much

(I need 10 rep to post images so i linked them..if thats against the rules im sorry but i didnt know how else to show you the problem!)

enter image description hereenter 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


}

Upvotes: 0

Views: 59

Answers (2)

brkr
brkr

Reputation: 1272

I found out the reason why.

These are the steps I took.

  1. Opened my Projects info.plist file Added a Key called

  2. NSAppTransportSecurity as a Dictionary.

  3. Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES as like following image.

Upvotes: 0

Punit
Punit

Reputation: 1340

Do these while working with tableview

  1. set datasource and delegate first
  2. and give proper outlets
  3. and implement numberOfRows and cellForRowAtIndexPath method properly
  4. and check wether your cell's height is proper

Upvotes: 2

Related Questions