Search code examples
iosswifttableviewuipopovercontrollerpopover

Show viewController swift


I have a tableView and i made its cells custom and added a UIButton to the cell i want when i press the button to popOver a new ViewController and in it the text in the cell i clicked the button in it. I don't want to use didSelectRowAtIndexPath func, i want to use the event of the button in each cell.

I tried to connect the button with the new viewController using popOver segue but the build fails because it is dynamic.

Please help and make the answer in swift. Thanks in advance


Solution

  • You shouls set target to button inside the cell in cellForRowAtIndexPath function

     cell.button.addTarget(self, action: "showPopupPage:", forControlEvents: UIControlEvents.TouchUpInside)
    

    create a function

      func showPopupPage(sender: UIButton) {
        let view = button.superview!
        let cell = view.superview as! custom cell
        // you can get cell contents here
    
     // call your popupview pass the value 
     }
    

    Example=> Swift - UIPopoverController in iOS 8