在ScrollView中实现TableView不会显示该表

问题描述 投票:0回答:1

没有花一天没有卡住。我试图在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()语句未在控制台中打印任何内容

ios swift uitableview tableview
1个回答
0
投票

由于tableView已经在堆栈视图中,请尝试将tableView的高度设置为-200。此外,请尝试向tableView添加背景,这样您就可以知道tableView正在占用适当的空间。关于未调用委托方法的问题,如果tableView本身不在屏幕上,则没有必要调用这些方法。所以我认为它不会被调用。

© www.soinside.com 2019 - 2024. All rights reserved.