首页 > 解决方案 > 在扩展文件 Swift 5.3 的范围内找不到类型“”

问题描述

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
    }
    
}

标签: swiftxcode12

解决方案


推荐阅读