Reputation: 1272
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!)
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
Reputation: 1272
I found out the reason why.
These are the steps I took.
Opened my Projects info.plist file Added a Key called
NSAppTransportSecurity as a Dictionary.
Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES as like following image.
Upvotes: 0
Reputation: 1340
Do these while working with tableview
numberOfRows
and cellForRowAtIndexPath
method properlyUpvotes: 2