Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to change style of table cell when using rx_subscribeRowsToCellWithIdentifier? #354

Closed
gferreri opened this issue Dec 23, 2015 · 2 comments

Comments

@gferreri
Copy link

When using rx_subscribeRowsToCellWithIdentifier, the resulting cells can be swiped to reveal a red "Delete" button, but in my application I don't want this. Is there an easy way to override this behavior? There is also a stackoverflow question on this topic with no answers.

@kzaher
Copy link
Member

kzaher commented Dec 23, 2015

Hi @gferreri ,

We forward methods through reactive proxy to rx_setDelegate if set.
This is how you can do this.

class SimpleTableViewExampleViewController : ViewController, UITableViewDelegate {
    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let items = Observable.just([
            "First Item",
            "Second Item",
            "Third Item"
        ])

        items
            .bindTo(tableView.rx_itemsWithCellIdentifier("Cell", cellType: UITableViewCell.self)) { (row, element, cell) in
                cell.textLabel?.text = "\(element) @ row \(row)"
            }
            .addDisposableTo(disposeBag)


        tableView
            .rx_modelSelected(String)
            .subscribeNext { value in
                DefaultWireframe.presentAlert("Tapped `\(value)`")
            }
            .addDisposableTo(disposeBag)

        tableView.rx_setDelegate(self)
            .addDisposableTo(disposeBag)
    }

    func tableView(tableView: UITableView, editingStyleForRowAtIndexPath: NSIndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.None
    }
}

@gferreri
Copy link
Author

Thank you! That's exactly what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants