首页 > 解决方案 > UITableView 将行数调整为 StoryBoard 中的行数

问题描述

在此处输入图像描述

您好,我正在尝试将 tableView 中的行数自动修改为 = 我的数组中的计数。数据工作正常,并且相应地加载行数。然而,表格本身总是显示 4 行,它不会加载更多,即使加载较少也不会显示更少,正如您在图片中看到的那样。下面是我的脚本和设置。

extension FirstViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("click")
}
}

extension FirstViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      //  let a = UserDefaults.standard.integer(forKey: "RunwayRows")
       // return a
        return runways.count
    }

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.textLabel?.text = runways[indexPath.row].ident1
    print(runways.count)

    return cell
}
}

在此处输入图像描述

在此处输入图像描述 在此处输入图像描述

标签: uitableviewstoryboardtableviewswift5xcode11

解决方案


推荐阅读