没有花一天没有卡住。我试图在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,阅读/观看了如何进行操作的说明,但看来我还是做错了什么。附言从print()语句未在控制台中打印任何内容
由于tableView
已经在堆栈视图中,请尝试将tableView
的高度设置为-200。此外,请尝试向tableView
添加背景,这样您就可以知道tableView
正在占用适当的空间。关于未调用委托方法的问题,如果tableView
本身不在屏幕上,则没有必要调用这些方法。所以我认为它不会被调用。