问题描述
我尝试在项目中使用具有独立文件的扩展名,但是当我尝试实例化UIView
,UImage
,UITableViewDelegate
时,出现“无法在瓢状中找到类型”扩展程序中的类。如何解决此错误?
这是我的代码:
extension MenuView: UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return titleArray.count
}
func tableView(_ tableView: UITableView,viewForHeaderInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor.white
let button = UIButton(type: .system)
button.frame = CGRect(x: 0,y: 0,width: 344,height: 50)
button.addTarget(self,action: #selector(handleExpandClose),for: .touchUpInside)
button.tag = section
view.addSubview(button)
let titleLabel = UILabel()
titleLabel.text = ((titleArray[section] as NSArray)[0] as! String)
titleLabel.font = titleLabel.font.withSize(16)
titleLabel.textColor = UIColor.black
titleLabel.frame = CGRect(x: 40,y: 20,width: 80,height: 20)
view.addSubview(titleLabel)
let icon = UIImage(named: ((titleArray[section] as NSArray)[1] as! String))
let iconImage = UIImageView(image: icon)
iconImage.frame = CGRect(x:250,y:25,width: 15,height: 10)
view.addSubview(iconImage)
return view
}
func tableView(_ tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
if !subtitleArray[section].isExpanded {
return subtitleArray[section].names.count
}
return 0
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MenuCell",for: indexPath) as! MenuTableViewCell
cell.titleCell.text = ((subtitleArray[indexPath.section].names as NSArray)[indexPath.row] as! String)
cell.iconCell.image = UIImage.init(named: ((iconArray[indexPath.section] as NSArray)[indexPath.row] ) as! String)
return cell
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)