UITableView不能使动态注册的单元格出队

时间:2019-01-22 11:09:09

标签: uitableview storyboard

我在尝试使可重用单元出队时遇到了异常。当我将初始场景箭头设置为使用列表视图指向场景时,效果很好,但是当我尝试在运行时加载场景时,出现异常

  

“无法使标识符为SessionListTableViewCell的单元出队-必须为该标识符注册一个笔尖或一个类,或者在情节提要中连接原型单元”

异常发生在调用tableView.dequeueReusableCell的地方

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    guard let cell = tableView.dequeueReusableCell(withIdentifier: "SessionListTableViewCell", for: indexPath) as? SessionListTableViewCell else {
        fatalError("The dequed cell is not an instance of SessionListTableViewCell")
    }

我很确定我已经在IB中正确注册了单元格类型。正确的单元格类型在IB中作为ListViewTableController的子级出现,并且“内容”设置为“动态原型”。

如果我将初始场景箭头设置为指向场景,则可以使用。如果我尝试在运行时加载同一场景,那将不起作用。我的表视图单元格标识符似乎已在IB中正确配置。

由于在此处出现编译错误,因此无法在代码中注册单元格类型: tableView.register(SessionListTableViewCell.self,forCellWithReuseIdentifier:“ SessionListTableViewCell”) “无法使用类型为((SessionListTableTableViewCell.Type,forCellWithReuseIdentifier:String)的参数列表调用'register'

1 个答案:

答案 0 :(得分:0)

我没有从情节提要中正确加载ViewController。

以下是正确的代码,以防其他人遇到此问题:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let poseViewController : PoseViewController = storyboard.instantiateViewController(withIdentifier: "Pose Menu") as! PoseViewController
self.present(poseViewController, animated: true, completion: nil)

您首先需要为UIViewController提供一个故事板标识符,如这篇文章所示:How do I give an "identifier" to a view controller within my storyboard?