如何解决单击菜单时 CocoPod SideMenu 不起作用
我有一个带有 CollectionView 的视图控制器,其中包含图像。
当我尝试使用 TableView 向其添加 SideMenu 时,点击栏按钮 'NSinvalidargumentexception',reason: 'must pass a class of kind UITableViewCell'
我正在使用本教程来实现 this
这是我的 ViewController 类
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
,这就是您收到错误的原因
在 viewDidLoad()
的 MenuListController
中,
添加
tableView.register(UITableViewCell.self,forCellReuseIdentifier: "cellmenu")
代替
tableView.register(UITableView.self,forCellReuseIdentifier: "cellmenu")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。