无法在 table 视图 Swift 上显示任何内容
Not able to display anything on table view Swift
这是我的历史视图,我在视图控制器中有一个表视图。但出于某种原因我无法输出任何内容,我试图对其进行硬编码并且它根本不显示任何内容。我知道的一件事是我需要覆盖 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)
}
}
这是我的 class 单元格原型,我确保标识符也是 "historyCell"
public class historyCell: UITableViewCell{
@IBOutlet var durationLabel: UILabel!
@IBOutlet var kicksLabel: UILabel!
}
您如何将原型单元格的控件连接到 historyCell class 中的 IBOutlets?当您不使用 UITableviewController 时,我不知道这是可能的。我一直在使用标签。
除非有一些我不知道的新东西,否则你对 cell.durationLabel.text 的赋值应该会导致 nil 的展开(这是你遇到的错误吗?)
这是我的历史视图,我在视图控制器中有一个表视图。但出于某种原因我无法输出任何内容,我试图对其进行硬编码并且它根本不显示任何内容。我知道的一件事是我需要覆盖 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)
}
}
这是我的 class 单元格原型,我确保标识符也是 "historyCell"
public class historyCell: UITableViewCell{
@IBOutlet var durationLabel: UILabel!
@IBOutlet var kicksLabel: UILabel!
}
您如何将原型单元格的控件连接到 historyCell class 中的 IBOutlets?当您不使用 UITableviewController 时,我不知道这是可能的。我一直在使用标签。
除非有一些我不知道的新东西,否则你对 cell.durationLabel.text 的赋值应该会导致 nil 的展开(这是你遇到的错误吗?)