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

前端 未结 4 1114
南旧
南旧 2021-01-20 18:46

I\'m new to app development and I\'m following Apple\'s tutorial to learn. I\'ve looked through a lot of questions asked about this type of error but none of them are helpin

相关标签:
4条回答
  • 2021-01-20 19:30

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

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

    I hope this help you.

    0 讨论(0)
  • 2021-01-20 19:36

    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

    0 讨论(0)
  • 2021-01-20 19:38

    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

    0 讨论(0)
  • 2021-01-20 19:41

    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)

    0 讨论(0)
提交回复
热议问题