【问题标题】:I do not understand why my cell is not showing up?我不明白为什么我的手机没有出现?
【发布时间】:2020-07-18 08:13:38
【问题描述】:

我不明白为什么我的单元格没有显示,即使我有正确的标识符和类

class homeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {





override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    
}

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    print("p")
    let cell: homeTableViewCell = tableView.dequeueReusableCell(withIdentifier: "homeTableViewCell", for: indexPath) as! homeTableViewCell
    
    return cell
} 

}

表格视图单元格和此处的标识符相同

【问题讨论】:

  • 这些函数都被调用了吗?
  • 添加断点进行测试
  • 你设置数据源了吗?
  • 是的,我确实设置了数据源
  • ` 类 homeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { `

标签: ios swift uitableview cell


【解决方案1】:

请为您的表格视图设置委托和数据源。

例如:

this.tableView.delegate = self
this.tableView.dataSource = self

【讨论】:

    【解决方案2】:

    给你的 tableview 下药并设置一个名字。假设您设置的名称 myTableView 。 在 viewDidLoad() 中写下这两行代码。

    myTableView.delegate = self
    myTableView.dataSource = self
    

    或者在 storyboard 中,按住 ctrl 并用鼠标左键点击 storyboard 视图控制器的顶部标题,然后启用 delegate 和 dataSource 。

    希望问题能解决。 如果您在此处有任何问题评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 2011-01-26
      • 2019-06-21
      • 2020-06-02
      • 2012-05-03
      相关资源
      最近更新 更多