DianQK / Flix

iOS reusable form library in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why my `tap action` is not working?

angelen10 opened this issue · comments

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?

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.

@DianQK Thanks a lot 😁