Eureka: onCellSelected never called on custom ButtonRow

Created on 21 Apr 2016  路  3Comments  路  Source: xmartlabs/Eureka

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.

onCellSelection custom row

Most helpful comment

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.

All 3 comments

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings