【问题标题】:Implementing TableView in ScrollView doesn't show the table在ScrollView中实现TableView不显示表格
【发布时间】:2020-05-06 09:00:51
【问题描述】:

没有一天没有卡住。我试图在 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上添加了适当的约束?
  • @sats 正确的是什么?我对所有边界都有约束 0 0 0 0,就是这样
  • @sats 我更害怕没有调用 tableView 函数的问题,因为控制台中没有打印语句的输出
  • 如果您使用原型单元格,则不得注册单元格。
  • @Golgi 由于 tableView 已经在堆栈视图中,请尝试将 tableView 的高度设置为 200。另外,尝试为 tableView 添加背景,以便您知道 tableView占用了适量的空间。关于未调用的委托方法,如果 tableView 本身不在屏幕上,则调用这些方法毫无意义。所以我认为它不会被调用。

标签: ios swift uitableview tableview


【解决方案1】:

由于tableView 已经在堆栈视图中,请尝试将tableView 的高度设置为200。另外,尝试为tableView 添加背景,以便您知道@987654324 是否@ 占用了适量的空间。关于不调用委托方法,如果tableView 本身不在屏幕上,则调用这些方法毫无意义。所以我认为它不会被调用。

【讨论】:

    猜你喜欢
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多