单击菜单时 Cocoa Pod 侧边菜单不起作用

CocoPod SideMenu not working when clicking menu

我有一个带有 CollectionView 的视图控制器,其中包含图像。

当我尝试使用 TableView 添加 SideMenu 时,我在点击栏按钮 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewCell'

时收到以下错误

我正在使用本教程来实现 this

此错误的任何原因?我应该改变什么?

这是我的ViewControllerClass

import SideMenu
import UIKit

class ViewController: UIViewController {
    var menu: SideMenuNavigationController?
    
    @IBOutlet weak var collectionView: UICollectionView!
    var imgArr = ["1","2","3"]
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        menu = SideMenuNavigationController(rootViewController: MenuListController())
        menu?.leftSide = true
        SideMenuManager.default.leftMenuNavigationController = menu
        SideMenuManager.default.addPanGestureToPresent(toView: self.view)
    }
    
    @IBAction func didTapMenu(){
        present(menu!, animated: true)
    }

}


extension ViewController : UICollectionViewDataSource, UICollectionViewDelegate{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imgArr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        var cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? DataCollectionViewCell
        cell?.img.image = UIImage(named:imgArr[indexPath.row])
        return cell!
    }
    
}

class MenuListController:UITableViewController{
    
    var items = ["First", "Second"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UITableView.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
    }
    
    
}

您必须注册 UITableViewCell 而不是 UITableView,这就是您收到错误的原因

MenuListControllerviewDidLoad() 中,

添加

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellmenu")

而不是

tableView.register(UITableView.self, forCellReuseIdentifier: "cellmenu")