You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CocoaPod SideMenu点击报错'must pass a class of kind UITableViewCell'如何解决?

问题解答

报错成因

  • 错误出现在侧边栏对应的MenuListController类的视图加载逻辑中:你给UITableView注册可复用单元格时,错误传入了UITableView.self作为待注册的类,而UITableView并非UITableViewCell的子类,完全不符合TableView单元格注册的类型要求,因此触发了该类型校验异常。

修复方案

将MenuListController的viewDidLoad方法中注册单元格的代码修改为传入正确的UITableViewCell.self即可,修改后的完整MenuListController代码如下:

class MenuListController: UITableViewController{
    
    var items = ["First", "Second"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 修正注册的类为UITableViewCell类型
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellmenu")
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellmenu", for: indexPath)
        cell.textLabel?.text = items[indexPath.row]
        return cell
    }
}

内容的提问来源于stack exchange,提问作者user1163234

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 07:24:04