Unrecognized selector sent to instance tableview swift

810 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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.