0
votes

My storyboard looks like this

StoryBoard

enter image description here

and my code is the following

UIViewController

class DownLoadSoundsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

// MARK: View Controller Properties
let viewName = "DownLoadSoundsViewController"
@IBOutlet weak var visualEffectView: UIVisualEffectView!
@IBOutlet weak var dismissButton: UIButton!
@IBOutlet weak var downloadTableView: UITableView!

// MARK: Properties
var soundPacks = [SoundPack?]()  // structure for downloadable sounds

override func viewDidLoad() {
    super.viewDidLoad()

    downloadTableView.dataSource = self
    downloadTableView.delegate = self
    downloadTableView.register(DownLoadTableViewCell.self, forCellReuseIdentifier: "cell")
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return numberOfSoundPacks
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let method = "tableView.cellForRowAt"

    //if (indexPath as NSIndexPath).section == 0 {

    let cell = tableView.dequeueReusableCell(withIdentifier: "downloadTableViewCell", for: indexPath) as! DownLoadTableViewCell

    cell.backgroundColor = UIColor.green

    if soundPacks[(indexPath as NSIndexPath).row]?.price == 0 {
        cell.soundPackPriceUILabel.text = "FREE"
    } else {
        cell.soundPackPriceUILabel.text = String(format: "%.2", (soundPacks[(indexPath as NSIndexPath).row]?.price)!)
    }

    //cell.textLabel?.text = soundPacks[(indexPath as NSIndexPath).row]?.soundPackTitle
    cell.soundPackTitleUILabel.text = soundPacks[(indexPath as NSIndexPath).row]?.soundPackTitle
    cell.soundPackAuthorUILabel.text = soundPacks[(indexPath as NSIndexPath).row]?.author
    cell.soundPackShortDescription.text = soundPacks[(indexPath as NSIndexPath).row]?.shortDescription

    cell.soundPackImage.image = UIImage(named: "Placeholder Icon")
    DDLogDebug("\(viewName).\(method): table section \((indexPath as NSIndexPath).section) row \((indexPath as NSIndexPath).row))")

    return cell
    //}
}

UItableViewCell

class DownLoadTableViewCell: UITableViewCell {

@IBOutlet weak var soundPackImage: UIImageView!    
@IBOutlet weak var soundPackTitleUILabel: UILabel!
@IBOutlet weak var soundPackAuthorUILabel: UILabel!
@IBOutlet weak var soundPackShortDescription: UILabel!
@IBOutlet weak var soundPackPriceUILabel: UILabel!

let gradientLayer = CAGradientLayer()

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

But I get the following;

Result - UGH!

I am sure I am doing something small incorrectly, but as of yet can't figure it out. Looked through many examples included my own code where I have gotten this working before.

Not a single one of my settings for the tableview are getting invoked except the number of cells. But everything in;

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{...}

is not working.

Help is appreciated.

1
Can you print numberOfSoundPacks.count? I think it's an empty array. - Danh Huynh
Yes. It's 3. but that might be it. It's set after a return call from firebase. So possible that it's not set in time. will try and let you know. - zenmobi
okay! Did you reload the tableView after getting data from Firebase? downloadTableView.reloadData() - Danh Huynh
You're awesome. That was it. needed to add self.downloadTableView.reloadData() Now, works like a charm. duh. been staring at this code too long. - zenmobi
yess! I added a answer, please accept it to help other people. - Danh Huynh

1 Answers

0
votes

I think you need to reload the tableView after getting data from Firebase

self.saveMixesTableView.reloadData()