代码之家  ›  专栏  ›  技术社区  ›  J.Doe2

Tableview在一行上创建五行?

  •  0
  • J.Doe2  · 技术社区  · 6 年前

    我有一个带有自定义单元格的tableView,我告诉它应该给我5个单元格作为该自定义单元格的返回。现在的问题是,我正在运行该应用程序,一行中有五行。我已经将单元格的默认大小更改为自定义大小,但这几乎是我所做的唯一一件事。所以现在我想知道是什么造成了这种问题?

    Broken tableView image

    我的tableView的代码如下所示。

    swift editor

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "theoryCell") as! theoryTVC
    
        return cell
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   rmaddy    6 年前

    所以,问题是您使用的是具有自定义高度的自定义单元格,但您没有在表视图方法中设置行的高度。

    试试这个:

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
    {
        return 100.0 //Choose your custom row height
    }