Ios 永远不会调用Tableview方法

Ios 永远不会调用Tableview方法,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个iOS应用程序,我在Interface Builder的视图中添加了一个UITableView。然后我在UIViewController中设置tableview,如下所示: tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 50 tableView.delegate = self tableView.dataSource = self tableView.contentIn

我有一个iOS应用程序,我在Interface Builder的视图中添加了一个
UITableView
。然后我在
UIViewController
中设置tableview,如下所示:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 50
tableView.delegate = self
tableView.dataSource = self
tableView.contentInset = UIEdgeInsets(top: 25, left: 0, bottom: 0, right: 0)
我还实施了以下方法:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    print("test table")
    let course = self.courses[indexPath.row]
    let cell = tableView.dequeueReusableCell(withIdentifier: CourseTableViewCell.identifier, for: indexPath) as! CourseTableViewCell

    cell.make(course, location: self.currentLocation)

    return cell
}

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return courses.count
}
但是,这些方法从未被调用,表视图没有被显示,我的控制台中没有错误?在尝试添加此内容时,是否有遗漏的内容

谢谢

根据评论中的要求:

  • 课程
    数组不是空的
  • courses
    数组在
    reloadData()
只需尝试实现“heightForRowAtIndexPath” 我认为您的表已正确重新加载,但由于单元格中的限制 UITableViewAutomaticDimension不工作。
2-确保课程分配正确,使用numberOfRowsAtIndexPath中的调试器检查课程中的项目

您应该通过在numberOfSections或numberOfRowsInSection等方法中设置断点来测试委托方法是否执行


当断点未命中时,代理设置不正确。

请尝试以下操作,而不是代码:

@IBOutlet weak var tableView: UITableView!{
    didSet {
        self.tableView.delegate = self
        self.tableView.dataSource = self
    }
}
确保控制器符合两个协议:
UITableViewDelegate
UITableViewDataSource

然后添加此方法以确保单元格的高度不为0分:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 80 // adjust height of row as needed 
}

您是否已将TableView链接到代码作为IBOutlet?@ReinierMelian是的,它已链接:
@IBOutlet弱var TableView:UITableView
你在哪里调用
tableView.reloadData()
?@vadian它在
viewDidLoad()
中被调用是
courses
空的?numberOfRows方法中的课程数/长度是多少?一个插座的属性观察员不是一个好建议。最合适的方法是在Interface Builder中连接数据源和委托