无法识别的选择器已发送至实例-UI按钮-Swift

问题描述

我正在以编程方式创建一个按钮,并在VC的扩展中添加了一个动作。另外,有没有比隐藏它们更好的方法来“删除”视图

func() setUpViews { 

    //views
    let shadowView = UIView(frame: CGRect(x: Int((UIScreen.main.bounds.width) - CGFloat(width)) / 2,y: (Int(UIScreen.main.bounds.height)),width: width,height: height))
    shadowView.backgroundColor = .none
    let mainView = UIView(frame: CGRect(x: 0,y: 0,height: height))
    let blackView =  UIView(frame: CGRect(x: 0,y: Int(self.navBar.bounds.height),width: 
    Int(UIScreen.main.bounds.width),height: Int(self.rewardsTableView.bounds.height)))
    shadowView.setUpViewShadowForCell()
    blackView.backgroundColor = .black
    blackView.alpha = 0
    mainView.backgroundColor = color
    mainView.layer.cornerRadius = 10
    mainView.clipsToBounds = true
    mainView.alpha = 1
    


    //close Button
    let closeButton = UIButton(frame: CGRect(x: CGFloat((Int(UIScreen.main.bounds.width) - width) / 
    2),y: CGFloat((Int(UIScreen.main.bounds.height) - height) / 2) + mainView.bounds.height,width: 
    mainView.bounds.width,height: 50))
    closeButton.backgroundColor = UIColor.black.withAlphaComponent(0.8)
    closeButton.tintColor = .white
    closeButton.setTitle("Close",for: .normal)
    closeButton.layer.cornerRadius = 10
    closeButton.addTarget(self,action: Selector(("closeAction")),for: .touchDown)

这是我要运行的功能。本质上,我想删除显示的视图。目前,我正在隐藏它们,并且出现错误“无法识别的选择器”。

    //function to revert back to original,currently hiding
    func closeAction(sender: AnyObject) {
        blackView.isHidden = true
        mainView.isHidden = true
    }

    //adding the views
    self.view.addSubview(shadowView)
    self.view.addSubview(blackView)
    self.view.addSubview(closeButton)
    shadowView.addSubview(mainView)
    self.view.bringSubviewToFront(shadowView)
   
}

试过这个:

     @objc func closeAction(sender: UIButton,UIView: UIView,UIView2: 
     UIView,Button1: UIButton) {
     UIView.removeFromSuperview()
     UIView2.removeFromSuperview()
     Button1.removeFromSuperview()
     }

在实际功能中:

    closeAction(sender: closeButton,UIView: shadowView,UIView2: 
    mainView,Button1: closeButton)
    closeButton.addTarget(self,action: #selector(closeAction),for: 
    .touchDown)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)