UIButton不添加目标Swift

时间:2019-05-19 14:58:35

标签: swift uibutton

我有一个UIButton,它已添加到stackView中。我在viewcontroller中有一个pagecontroller,并添加了stackView进行查看。一切显示良好,但是当我将目标添加到创建的按钮时,从我创建的目标进行打印时什么也没有发生。我对此感到困惑。任何帮助将不胜感激。

13

在viewDidLoad中调用的我的逻辑函数:

let nextBtn: UIButton = {
    let nextBtn = UIButton()
    nextBtn.translatesAutoresizingMaskIntoConstraints = false
    nextBtn.setTitle("Next", for: .normal)
    nextBtn.backgroundColor = .red
    return nextBtn
}()

我的objc函数:

fileprivate func layout() {
    view.addSubview(nextBtn) 

    NSLayoutConstraint.activate([
        nextBtn.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -30),
        nextBtn.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
        nextBtn.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
        nextBtn.heightAnchor.constraint(equalToConstant: 44),
        ])

    nextBtn.addTarget(pageController.self, action: #selector(nextBtnClicked), for: .touchUpInside)
}

0 个答案:

没有答案