微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在扩展文件Swift 5.3的独家新闻中找不到类型“”

如何解决在扩展文件Swift 5.3的独家新闻中找不到类型“”

我尝试在项目中使用具有独立文件的扩展名,但是当我尝试实例化UIViewUImageUITableViewDelegate时,出现“无法在瓢状中找到类型”扩展程序中的类。如何解决错误

enter image description here

这是我的代码

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 举报,一经查实,本站将立刻删除。