iphone - 无法在 TableView Swift 上显示任何内容

标签 iphone swift uikit overriding tableview

这是我的历史 View ,我在 View Controller 中有一个 TableView 。但由于某种原因,我无法输出任何内容,我试图对其进行硬编码,但它根本不显示任何内容。我知道的一件事是我需要覆盖 tableView 函数,如果我这样做就会出错。

  import UIKit

    class History: UIViewController, UITableViewDataSource, UITableViewDelegate
    {

    @IBOutlet var tableView: UITableView!

    override func viewDidLoad()
    {
        super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self

        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "newBackground.jpg")!)
    }

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


    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCellWithIdentifier("historyCell", forIndexPath: indexPath) as! historyCell

        cell.durationLabel.text = "98"

        return cell
    }


    override func viewWillAppear(animated: Bool)
    {
        super.viewWillAppear(animated)

    }

}

这是我的单元原型(prototype)类,我确保标识符也是“historyCell”

public class historyCell: UITableViewCell{
    @IBOutlet var durationLabel: UILabel!
    @IBOutlet var kicksLabel: UILabel!

}

最佳答案

您如何将原型(prototype)单元的控件连接到historyCell 类中的IBOutlet?我不知道当你不使用 UITableviewController 时这是可能的。我一直在使用标签。

除非有我不知道的新内容,否则您对 cell.durationLabel.text 的分配应该会导致 nil 的展开(这是您收到的错误吗?)

关于iphone - 无法在 TableView Swift 上显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34822310/

相关文章:

iphone - 在 iOS 中加密和解密密码

ios - 获取 Firebase 列中的所有数据

ios - Swift:使用静态表时,索引路径中的选择行是否返回 nil

ios - UIKit 和 GCD 线程安全

ios - 移动一个 UIImageView

ios - 为 UIBezierPath 创建旋转动画

ios - 应用评论多久会出现在 iTunes Connect 中?

ios - 如何在 Storyboard上为 xcode 中的所有设备定位按钮

javascript - iPhone 的网页 - 大字体而不是滚动?

swift - Swift 3 中的 Pip (Python) 等价物是什么?