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

onCellSelected never called on custom ButtonRow #390

Closed
allanrojas opened this issue Apr 21, 2016 · 3 comments
Closed

onCellSelected never called on custom ButtonRow #390

allanrojas opened this issue Apr 21, 2016 · 3 comments

Comments

@allanrojas
Copy link

Hey,

This is probably an easy one, but I'm breaking my head here and have wasted a lot of time with no solution. I created a very simple custom "SUBMIT" button row with its own custom cell, the cell only has one button called titleButton, here's the setup of the cell:

    public override func setup() {
        super.setup()
        titleButton.setTitle(row.value, forState: .Normal)
        titleButton?.addTarget(self, action: #selector(VIBlueButtonCell.onTitleButtonPressed), forControlEvents: .TouchUpInside)
    }

Then I add it to my form like this:

        section <<< VIBlueButtonRow() { row in
            row.value = "Submit"
        }.onCellSelection({ (cell, row) in
            print("cell selected?")
        })

I want the cell to get selected when onTitleButtonPressed is called; but so far I can't figure it out... I have tried all of the following commented lines, none seem to work:

    public func onTitleButtonPressed() {
//        super.baseRow.select(true)
//        self.baseRow.baseCell.setSelected(true, animated: true)
//        self.setSelected(true, animated: true)
//        self.formCell()?.setSelected(true, animated: true)
//        self.select(nil)
//        self.formCell()?.select(nil)
//        self.baseRow.baseCell.select(nil)
    }

Any ideas? It doesn't have to be "onCellSelection", any of the other row methods will do. What I need is a way of knowing - at the form level - that the custom button was pressed, so i can process the form values.

@mats-claassen
Copy link
Member

OnCellSelection should be automatically called when the cell is selected. You could try with cell.didSelect() but that should happen automatically, unless obviously the button's action is triggered instead of the cell selection.
What happens if you remove the line:
titleButton?.addTarget(self, action: #selector(VIBlueButtonCell.onTitleButtonPressed), forControlEvents: .TouchUpInside)
Nevertheless, cell.didSelect() should work for you

@allanrojas
Copy link
Author

This is a custom row with a UIButton in it, if I remove the "addTarget" code, nothing happens when I press the button. :(

@allanrojas
Copy link
Author

I got it...

"onTitleButtonPressed" is a method located in the cell, not the row, and what I wanted to call was the row's "onCellSelection" method... so the fix is this:

    public func onTitleButtonPressed() {
        self.baseRow.didSelect()
    }

And now I can intercept the "onCellSelection" method at the form level.

Thanks for the help, you can close this issue now.

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

No branches or pull requests

3 participants