Mon story-board ressemble à ceciSwift -> ma cellule prototype (UITableViewCell) ne montre pas dans mon UIViewController avec un UITableView
et mon code est le
suivantUIViewController
classe DownLoadSoundsViewController: UIViewController, UITableViewDataSour CE, 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
classe 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
}
}
Mais j'obtiens ce qui suit;
Je suis sûr que je suis en train de faire quelque chose de petit mal, mais pour l'instant ne peut pas comprendre. Regardé à travers de nombreux exemples inclus mon propre code où j'ai obtenu ce travail avant.
Aucun de mes paramètres pour la vue de table n'est invoqué à l'exception du nombre de cellules. Mais tout dans;
func tableView (_ tableView: UITableView, cellForRowAt indexPath: indexPath) -> UITableViewCell {...}
ne fonctionne pas.
L'aide est appréciée.
Pouvez-vous imprimer 'numberOfSoundPacks.count'? Je pense que c'est un tableau vide. –
Oui. C'est 3. mais ça pourrait être ça. Il est défini après un appel de retour de Firebase. Donc possible que ce ne soit pas dans le temps. va essayer et vous faire savoir. – zenmobi
okay! Avez-vous rechargé la tableView après avoir obtenu des données de Firebase? 'downloadTableView.reloadData()' –