这是我的历史 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/