Событие щелчка UIB-кнопки subview не работает из ViewController swift 4 - PullRequest
0 голосов
/ 10 октября 2018

Мой заказ EmptyUIView.Я хочу позвонить UIView uiBtnExplore с UIViewController.

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

1 Ответ

0 голосов
/ 10 октября 2018

Вы отключили userInteraction с вашим представлением, когда вы отключили взаимодействие с пользователем, оно отключило взаимодействие со всеми его подпредставлениями, которые меняются ниже строки

view.isUserInteractionEnabled = false

С

view.isUserInteractionEnabled = true
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...