Swift unrecognized selector sent to instance error

前端 未结 3 1280
渐次进展
渐次进展 2020-12-21 21:05

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

3条回答
  •  -上瘾入骨i
    2020-12-21 22:05

    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!) { ... 
    

提交回复
热议问题