I recently converted my project from Objective-C to Swift and in doing so I acquired this error whenever I click a button in the table view\'s cell. I have multiple cells be
For Swift 2.2
with Xcode 8
:
self.followedButton.addTarget(parentView, action: #selector(CustomCell.followButtonClick(_:)), forControlEvents: .TouchUpInside)
For Swift3
, you need to change the following:
self.followedButton.addTarget(parentView, action: Selector(("followedButtonClick")), for: .touchUpInside)
With:
self.followedButton.addTarget(parentView, action: #selector(self.followButtonClick(_:)), forControlEvents: .touchUpInside)
Two changes for Swift 3:
The selector should look like:
#selector(ClassName.followButtonClick(_:))
The function should have an underscore:
@IBAction func followButtonClick(_ sender: UIButton!) { ...
Notice that these two should be in the same class, otherwise, make sure you initialize the ClassName
class.
If you want the selector method(followButtonClick(_:)
) to be in the UITableViewCell
class. Remove @IBAction
(I don't think you need it there):
func followButtonClick(_ sender: UIButton!) { ...