Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 子视图UIButton单击事件无法从ViewController swift 4工作_Ios_Swift_Uibutton - Fatal编程技术网

Ios 子视图UIButton单击事件无法从ViewController swift 4工作

Ios 子视图UIButton单击事件无法从ViewController swift 4工作,ios,swift,uibutton,Ios,Swift,Uibutton,我的自定义EmptyUIView。我想从UIViewController调用uiBtnExplore class EmptyView: UIView { @IBOutlet weak var uiBtnExplore: UIButton! class func createEmptyView() -> EmptyView { let myEmptyNib = UINib(nibName: "EmptyView", bundle: nil)

我的自定义
EmptyUIView
。我想从
UIViewController
调用
uiBtnExplore

class EmptyView: UIView {
    @IBOutlet weak var uiBtnExplore: UIButton!

    class func createEmptyView() -> EmptyView {
        let myEmptyNib = UINib(nibName: "EmptyView", bundle: nil)
        return myEmptyNib.instantiate(withOwner: nil, options: nil)[0] as! EmptyView
    }
}
我的UIViewController:

import UIKit
import XLPagerTabStrip

class PlaylistViewController: UIViewController, IndicatorInfoProvider {
    var itemInfo: IndicatorInfo = "PLAYLISTS"
    var emptyView:EmptyView!

    func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
        return itemInfo
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        emptyView = EmptyView.createEmptyView()
        self.emptyView.center = CGPoint(x: view.frame.size.width  / 2,
                                        y: view.frame.size.height / 2)
        self.view.addSubview(emptyView)
        self.view.bringSubviewToFront(testButton)
        view.isUserInteractionEnabled = false

        self.emptyView.uiBtnExplore.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
    }

    @objc func buttonAction(sender: UIButton!) {
        print("Button Clicked")
    }
}

您已经禁用了与视图的用户交互,当您禁用用户交互时,它将禁用与其所有子视图的交互,并在第行下方更改

view.isUserInteractionEnabled = false

view.isUserInteractionEnabled = true

你撞车了吗?因为选择器似乎不正确,我认为它应该会崩溃,并出现“无法识别的选择器发送到实例”错误消息。但是执行
view.isUserInteractionEnabled=false也可能导致问题。否,我的视图显示正确,但在按钮单击“无”后happened@Tariqul尝试使用三维视图进行调试。确保此按钮不在其他视图后面或卡在其他视图上检查文档大纲中的视图层次结构。感谢您的评论,我收到了这个问题。当设置空视图大小自由并给出大小后,按钮单击不起作用,但当我给出推断时,按钮起作用,但我无法理解原因。谢谢您的回答,先生,我尝试了此操作,但仍然不起作用self.emptyView.uiBtnExplore.uiBtnExplore.addTarget(self,action:#选择器(buttonAction(sender:)),for:.touchUpInside)请为选择器尝试此选项,同时保持userInteraction Enabled如果此选项不起作用,请检查测试按钮的位置。它可能与uiBtnExplore重叠,或者可能是uiBtnExplore帧导致问题。我现在只添加空视图