Xcode - Terminating with uncaught exception of type NSException when a button is pressed

巧了我就是萌 提交于 2019-12-01 20:55:28

You're missing the ":" in the selector, try the following instead:

button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)

I hope this help you.

If you're using Swift 3, the line in question would have to be changed to:

button.addTarget(self, action: #selector(StarRatingControl.ratingButtonTapped), for: .touchDown)

dyngry

I had the same problem, Check the version of your Xcode.

#selector comes with Xcode 7.3

If you have an older version update and this will probably fix your errors.

Regards, Driss

For reference, I've decided to have a look at the sample and got a similar issue.

I'm using XCode 8 + Swift 3 and these are my changes in order to get it working:

button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped), for: .touchDown)

Note: considering the file name "RatingControl.swift".

I hope it help =D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!