I am trying to post a picture in a table view cell, but it keeps coming back blank. I have 3 files that I've created for this.
First is a data file with the picture information:
import Foundation
class Data {
class Entry {
let filename : String
let heading : String
init(fname : String, heading : String) {
self.heading = heading
self.filename = fname
}
}
let pic = [
Entry(fname: "Picture1.jpg", heading: "Heading 1"),
]
}
Then I have my table view controller
import UIKit
class TableViewController: UITableViewController {
let data = Data()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.pic.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell
let entry = data.pic[indexPath.row]
let image = UIImage(named: entry.filename)
cell.pic.image = image
return cell
}
}
The third is the cell itself
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet var selfie: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
I have no clue why the cell is coming back blank. I have the image file stored in Supporting Files.
Can anyone help me?
Aucun commentaire:
Enregistrer un commentaire