ios - Implementing TableView in ScrollView doesn't show the table
问题描述
haven't spent a day without a stuck. I was trying to implement TableView in a ScrollView, but it never showed up.
The code is here:
@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
}
}
And also a screen of StoryBoard StoryBoard
I checked the id of cell, tried to connect a tableView again, read/watched instructions how to do that, but it seems I am still doing something wrong. P.S. nothing is being printed in console from print() statement
解决方案
由于tableView
已经在堆栈视图中,请尝试将tableView
- 的高度设置为 200。此外,尝试为 添加背景tableView
,这样您就会知道 是否tableView
占用了适量的空间。关于不调用委托方法,如果它tableView
本身不在屏幕上,那么调用这些方法是没有意义的。所以我认为它不会被调用。
推荐阅读
- c - 让一个线程在C中多次运行一个函数
- java - 散列和保护传输中的数据
- docker - 有没有办法在同一主机上的 2 个 Elasticsearch 容器之间进行通信?
- android - 当我按下 onClick Android 时,按钮会收缩
- postgresql - 如何更新 PostgreSQL 数据库中 Java 地图的文本表示?
- node.js - MERN 这个相同的查询来自远程服务器的不同输出
- angular - Ionic 4/5 - 错误:路由:当标签页用作组件时
- spring-boot - Zuul 通过外部代理服务器路由请求
- javascript - 如何在chart.js中以k格式显示条形值的千位
- c# - 使用可选字段发布服务属性,但如果它为空或为空,则需要更新