0

In my cellFoRowAtIndexPath I want to add a function on a button that belongs to the cell.

In my cellFoRowAtIndexPath I have added this code.

cell.acceptBtn.addTarget(self, action: "acceptRequest", forControlEvents: .TouchUpInside)

And then I have this function here.

func acceptRequest(sender: UIButton) {
    println("hello"); 
}

When I run the project and click the button on that cell I get a

Terminating app due to uncaught exception 'NSInvalidArgumentException' unrecognized selector sent to instance

Something to note is I have another button that I used the same exact way called declineRequest which works perfectly fine.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
kareem
  • 903
  • 1
  • 14
  • 36
  • 1
    possible duplicate of [iOS unrecognized selector sent to instance in Swift](http://stackoverflow.com/questions/24153058/ios-unrecognized-selector-sent-to-instance-in-swift) – Eric Aya Aug 22 '15 at 22:51

1 Answers1

2

Try the following:

cell.acceptBtn.addTarget(self, action: "acceptRequest:", forControlEvents: .TouchUpInside)

… noting that it is "acceptRequest:" and not "acceptRequest". The latter implies that the function has no parameters.

dangnabit
  • 654
  • 3
  • 9
  • thanks ! it solved my issue... what a silly error but you just saved me will accept answer in 10 min when it lets me – kareem Aug 22 '15 at 22:50