Swift 3.0 调整表格视图大小时未填充表格单元格



我正在尝试创建一个适合iPad上一半屏幕的表格视图。

为此,我正在使用

tableView.frame = CGRect(x: tableView.frame.origin.x, y:     tableView.frame.origin.y, width: tableView.frame.size.width, height: tableView.contentSize.height)

注释掉此行后,表格视图将填充到整个屏幕,但会填充表格单元格。当它没有被注释掉时,它是正确的大小,但没有填充任何东西。

表单元格代码

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cellIdentifier = "cell"
    let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
        ?? UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
 cell.textLabel?.text = "test";
    return cell
}

想通了这个问题,现在我觉得自己很愚蠢。

我没有将表格与班级联系起来。所以我这样做了,并把它命名为leftTable。我删除了该行

tableView.frame = CGRect(x: tableView.frame.origin.x, y:     tableView.frame.origin.y, width: tableView.frame.size.width, height: tableView.contentSize.height)

并添加在

var tableView = self.leftTable;

它现在像一个魅力

最新更新