[swift-users] addTarget calling wrong method on some device.

c1708 poketo7878 at gmail.com
Fri Mar 4 09:01:31 CST 2016


Currently I’m implementing my app in Swift with latest Xcode.

On my application’s UIViewController I wrote:

if (Util.isFeatureEnabled(Feature.X)) {
      let xButton = UIButton()
      self.xButton = xButton
      xButton.addTarget(self, “xButtonTouched:”…)
let yButton = UIButton()
self.yButton = yButton
yButton.addTarget(self, “yButtonTouched:” …)
fun yButtonTouched(sender: UIButton) {

And I forget implement xButtonTouched function,
But feature-X is always disable(by some business reason),
so I think xButton never showed Up and Above code working correctly.
And working correctly on my device(iPhone 6 Plus) as expected.

But, I noticed on some others device(which include iPhone 6 Plus)
Get called xButtonTouched: when yButton Touched, and raise "unrecognized selector sent to instance” error.

I can’t understand why this error happened. Is error depend on device? Or nasal demon?

More information about the swift-users mailing list