在 ScrollView 中实现 TableView 不显示 table
Implementing TableView in ScrollView doesn't show the table
没有一天不卡住。我试图在 ScrollView 中实现 TableView,但它从未出现。
代码在这里:
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "logTableCell")
}
var logs: [String] = ["Data1", "Data12", "Data13", "Data14"]
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return logs.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "logTableCell", for: indexPath)
cell.textLabel?.text = logs[indexPath.row]
print("I am at table place")
return cell
}
}
还有StoryBoard的画面
StoryBoard
我检查了单元格的 ID,尝试再次连接一个 tableView,read/watched 说明了如何做到这一点,但似乎我仍然做错了。
P.S。 print() 语句
控制台中未打印任何内容
由于 tableView
已经在堆栈视图中,请尝试将 tableView
的高度设置为 200。此外,请尝试向 tableView
添加背景,因此你会知道 tableView
是否占用了正确数量的 space。关于未调用的委托方法,如果 tableView
本身不在屏幕上,则调用这些方法没有意义。所以我不认为它会被调用。
没有一天不卡住。我试图在 ScrollView 中实现 TableView,但它从未出现。
代码在这里:
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "logTableCell")
}
var logs: [String] = ["Data1", "Data12", "Data13", "Data14"]
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return logs.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "logTableCell", for: indexPath)
cell.textLabel?.text = logs[indexPath.row]
print("I am at table place")
return cell
}
}
还有StoryBoard的画面 StoryBoard
我检查了单元格的 ID,尝试再次连接一个 tableView,read/watched 说明了如何做到这一点,但似乎我仍然做错了。 P.S。 print() 语句
控制台中未打印任何内容由于 tableView
已经在堆栈视图中,请尝试将 tableView
的高度设置为 200。此外,请尝试向 tableView
添加背景,因此你会知道 tableView
是否占用了正确数量的 space。关于未调用的委托方法,如果 tableView
本身不在屏幕上,则调用这些方法没有意义。所以我不认为它会被调用。