マイストーリーボードとの私のUIViewControllerには表示されませんが、このスウィフト - >私のプロトタイプのセル(UITableViewCellのが)のUITableView
のように見え、私のコードは次のよう
ですUIViewController
クラス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
クラス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
}
}
は、しかし、私は次のように取得します。
私は私が間違って小さな何かをやっている確信しているが、まだのようにそれを把握することはできません。多くの例を見てみると、これまでに私が行ってきた自分のコードが含まれていました。
セルの数を除いて、テーブルビューの設定が1つも呼び出されていません。しかし、すべての。
FUNC用のtableView(_のtableView:のUITableView、cellForRowAt indexPath:IndexPath) - >のUITableViewCell {...}
が動作していません。
お手数ですが、
からのデータは、あなたが 'numberOfSoundPacks.count'を印刷することができます取得した後にtableViewをリロードする必要があると思いますか?私はそれが空の配列だと思う。 –
はい。それは3ですが、それはそれかもしれません。それはfirebaseからのリターンコールの後に設定されます。時間内に設定されていない可能性があります。あなたに知らせようとします。 – zenmobi
大丈夫です! Firebaseからデータを取得した後にtableViewをリロードしましたか? 'downloadTableView.reloadData()' –