0
votes

Here is my code :

@IBAction func moreClicked(_ sender: UIButton) {
    if sender.currentImage == #imageLiteral(resourceName: "more_off"){
        sender.setImage(#imageLiteral(resourceName: "more_on"), for: .normal)
    }
    else
    {
        sender.setImage(#imageLiteral(resourceName: "more_off"), for: .normal)
    }

}

I am getting this error:

2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989] -[musicPlayer.SecondViewController more:]: unrecognized selector sent to instance 0x7fc1d4606d00

2018-09-05 11:03:28.715659+0530 musicPlayer[25450:590989] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[musicPlayer.SecondViewController more:]: unrecognized selector sent to instance 0x7fc1d4606d00' * First throw call stack: ( 0 CoreFoundation 0x00000001087ea1e6 exceptionPreprocess + 294 1 libobjc.A.dylib
0x0000000107a36031 objc_exception_throw + 48 2 CoreFoundation
0x000000010886b784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 UIKit 0x0000000108e956db -[UIResponder doesNotRecognizeSelector:] + 295 4 CoreFoundation 0x000000010876c898 ___forwarding_
+ 1432 5 CoreFoundation
0x000000010876c278 _CF_forwarding_prep_0 + 120 6 UIKit
0x0000000108c683e8 -[UIApplication sendAction:to:from:forEvent:] + 83 7 UIKit 0x0000000108de37a4 -[UIControl sendAction:to:forEvent:] + 67 8 UIKit 0x0000000108de3ac1 -[UIControl _sendActionsForEvents:withEvent:] + 450 9 UIKit 0x0000000108de2a09 -[UIControl touchesEnded:withEvent:] + 580 10 UIKit 0x0000000108cdd0bf -[UIWindow _sendTouchesForEvent:] + 2729 11 UIKit 0x0000000108cde7c1 -[UIWindow sendEvent:] + 4086 12 UIKit
0x0000000108c82310 -[UIApplication sendEvent:] + 352 13 UIKit
0x00000001095c36af dispatchPreprocessedEventFromEventQueue + 2796 14 UIKit 0x00000001095c62c4 __handleEventQueueInternal + 5949 15 CoreFoundation 0x000000010878cbb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 16 CoreFoundation 0x00000001087714af __CFRunLoopDoSources0 + 271 17 CoreFoundation 0x0000000108770a6f __CFRunLoopRun + 1263 18 CoreFoundation
0x000000010877030b CFRunLoopRunSpecific + 635 19 GraphicsServices
0x000000010ff76a73 GSEventRunModal + 62 20 UIKit
0x0000000108c67057 UIApplicationMain + 159 21 musicPlayer
0x000000010711cc27 main + 55 22 libdyld.dylib
0x000000010cd4f955 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

1
your code is working perfect.Malleswari
Your IBActions are probably connected wrongly. Disconnect the action and connect it again. Or are you doing it programmatically with addTarget?Sweeper
I deleted the previous connection and connected it again. It works now, thank youPradnya Achari

1 Answers

0
votes

2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989] -[musicPlayer.SecondViewController more:]: unrecognized selector sent to instance 0x7fc1d4606d00

The above message means that SecondViewController expects to have method called more: but when the action is triggered and instance from this class tries to find the more: method, it does not recognise such method and the application crashes.

What I think has happened here is: you have dragged action from your Xib/Storyboard to your VC class and named it more:. After this you have renamed it manually (not Refactor > Rename) to moreClicked:. This way the IBAction of the SecondViewController still points to method that is called more:, however your class does not have such method anymore.

So basically, you need to remove the already existing reference of the IBAction from your xib/storyboard and reconnect it with the new method: moreClicked:, and all should be working.