Search code examples
iosswifteureka-forms

How do we perform a condition after we click on a cell using Eureka


I'm using the code below:

<<< ButtonRow("MyCell") { $0.title = $0.tag $0.presentationMode = .segueName(segueName: "ShowMyScreen", onDismiss: nil) }

Now, I need to perform a conditon on click and move only if it's true and show an alert if it's false. Then move if the user clicks on ok from the alert. How do I do that?


Solution

  • Use the .onCellSelection closure

    Example code of your requirements

    <<< ButtonRow("MyCell") { $0.title = $0.tag
                    }.onCellSelection({ (cell, row) in
                        if(yourCondition)
                        {
                           self.performSegue(withIdentifier: "ShowMyScreen", sender: nil)
                        }else{
                            let alert = UIAlertController(title: "test", message: "test", preferredStyle: .alert)
                            let action = UIAlertAction(title: "OK", style: .default, handler: { (action) in
                                self.performSegue(withIdentifier: "ShowMyScreen", sender: nil)
                            })
                            let action2 = UIAlertAction(title: "Cancel", style: .default, handler: nil)
                            alert.addAction(action)
                            alert.addAction(action2)
                            self.present(alert, animated: true, completion: nil)
                        }
                    })