我有一个带有自定义单元格的tableView,我告诉它应该给我5个单元格作为该自定义单元格的返回。现在的问题是,我正在运行该应用程序,一行中有五行。我已经将单元格的默认大小更改为自定义大小,但这几乎是我所做的唯一一件事。所以现在我想知道是什么造成了这种问题?
我的tableView的代码如下所示。
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 }
所以,问题是您使用的是具有自定义高度的自定义单元格,但您没有在表视图方法中设置行的高度。
试试这个:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 100.0 //Choose your custom row height }