Reputation: 2847
I'd like to use RxSwift in my project, but because I'm newbie I maybe misunderstand some principles. Its clear for me how to catch button presses or use rxswift with UITableView with dynamic cells (there are a lot of tutorials for that), but I don't understand how to use it with UITableView with STATIC cells - I'd like to develop something like iOS Settings.app. Could you show me example? Is it a good practice to use rxswift for it? Or maybe I should use something else?
Upvotes: 0
Views: 1011
Reputation: 33967
To handle static cells, you have to use a UITableViewController (which I assume you know) but you can still use the rx
operators on its tableView.
Of course you don't need to use the items
operator on it because the cells are already built, but you can still use itemSelected
to determine which cell was tapped on:
final class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.rx.itemSelected
.subscribe(onNext: { print("selected index path \($0)") })
.disposed(by: bag)
}
let bag = DisposeBag()
}
Upvotes: 0
Reputation: 1882
You can drag a @IBOutlet weak var button: UIButton!
from static table view cell button, So it's something like this:
class TableViewController: UITableViewController {
@IBOutlet weak var button: UIButton!
...
override func viewDidLoad() {
super.viewDidLoad()
...
button.rx.tap
.subscribe()
.disposed(by: disposeBag)
}
...
}
Hope this may help.
Upvotes: 1