按钮未显示在UITableViewCell

时间:2018-11-01 04:33:00

标签: ios xcode uitableview

我已经在主故事板上配置了一个表格视图,该表格在原型单元中具有一个按钮。但是,当我运行它时,表格视图单元格显示时没有按钮。这是我的情节提要的图片:

tableview

有人可以解释为什么当我运行该程序时它不会显示吗?

4 个答案:

答案 0 :(得分:0)

问题在于表格单元格的高度。由于单元格的高度很小,因此未显示按钮。您必须必须实现tableView heightForRowAt indexPath方法。

在此之前,将DelegateDtataSource方法分配给tableView。

override func viewDidLoad(){
        super.viewDidLoad()
                tableview.delegate = self
                tableview.datasource = self
}

如果已分配,则。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 105
    }

或者我想您也可以从“大小”检查器中调整高度,然后选中“自定义高度”框并提供自定义高度。并设置适当的约束。

enter image description here

答案 1 :(得分:0)

清单:

1。。将tableView's delegatedataSource设置为controller,即

tableView.delegate = self
tableView.dataSource = self

2。。检查height中的tableViewCell是否不是0

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 200.0 //Actual height of the cell
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 100.0
}

3。。您向constraints添加了什么button?尝试将centeredHorizontallycenteredVertically constraints添加到UIButton

答案 2 :(得分:0)

设置按钮的背景色,以便我们检查按钮是否被创建。或确保您可以添加UIButton的约束

答案 3 :(得分:0)

只需在UITableViewDataSource方法上放置一个断点即可。如果他们没有通话,则只需转到您的故事板文件,然后在视图控制器中设置tableview委托和数据源即可。enter image description here

相关问题