首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用UITableView时,Swift -> my prototype cell (UITableViewCell)不会显示在我的UIViewController中

使用UITableView时,Swift -> my prototype cell (UITableViewCell)不会显示在我的UIViewController中
EN

Stack Overflow用户
提问于 2017-03-29 10:38:40
回答 1查看 489关注 0票数 0

我的故事板看起来像这样

我的代码如下

UIViewController

类DownLoadSoundsViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

代码语言:javascript
运行
复制
// 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 {

代码语言:javascript
运行
复制
@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
}

}

但我得到了以下结论:

我确信我做了一些不正确的小事情,但到目前为止还不能弄清楚。查看了许多示例,包括我自己的代码,我以前在这些代码中得到了工作。

除了单元格的数量之外,我的表视图设置中没有一个会被调用。但是所有的东西都在;

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

不起作用。

感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-03-30 11:07:48

我认为在从Firebase获取数据后,需要重新加载tableView

代码语言:javascript
运行
复制
self.saveMixesTableView.reloadData()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43083316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档