DianQK / Flix

iOS reusable form library in Swift.
MIT License
726 stars 43 forks source link

Why my `tap action` is not working? #10

Closed angelen10 closed 6 years ago

angelen10 commented 6 years ago

I write the code in viewDidLoad function at my viewController:

let provider = WNFlixAddButtonProvider()
 provider.tap.subscribe(onNext: { _ in
        print("Ooops")
}).disposed(by: self.disposeBag)
tableView.flix.build([provider])

And WNFlixAddButtonProvider is just based on UniqueCustomTableViewProvider:

class WNFlixAddButtonProvider: UniqueCustomTableViewProvider {

    let addButton = UIButton().then {
        $0.backgroundColor = .red
        $0.setTitle("+ Work Experience", for: .normal)
        $0.setTitleColor(UIColor.blue, for: .normal)
        $0.titleLabel?.font = Specs.font.regular
    }

    override init() {
        super.init()

        contentView.addSubview(addButton)

        addButton.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
}

When I run the project, the UI look's perfect, but when I tap the addButton, it's not working.

I find some code at: Flix/Example/Example/LoginViewController.swift, the tap action works:

loginProvider.tap
            .withLatestFrom(isVerified).filter { $0 }
            .subscribe(onNext: { [weak self] _ in
                let alert = UIAlertController(title: "Success", message: nil, preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
                    self?.navigationController?.popViewController(animated: true)
                }))
                self?.present(alert, animated: true, completion: nil)
            })
            .disposed(by: disposeBag)

Some code I miss?

DianQK commented 6 years ago

Because you added a UIButton on contentView.

UniqueCustomTableViewProvider.tap just is a tableView selected cell event.

The loginProvider just added a UILabel on contentView not UIButton.

angelen10 commented 6 years ago

@DianQK Thanks a lot 😁