0

这是我的代码:

@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)
    }

}

我收到此错误:

2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989] -[musicPlayer.SecondViewController 更多:]:无法识别的选择器发送到实例 0x7fc1d4606d00

2018-09-05 11:03:28.715659+0530 musicPlayer[25450:590989] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[musicPlayer.SecondViewController 更多:]:无法识别的选择器发送到实例 0x7fc1d4606d00”*第一个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 核心基础
0x000000010876C278 _cf_forwarding_prep_0 + 120 6 Uikit
0x000000000108C683E8- [UIAPPLICITION SENDACTION:to:to:From:Forevent:] + 83 7 UIKIT 0X000000010108DE37A4- [UICONTROL 4- [UICONTROL 6- [UICONTROL 6. UICTROL 10 + iCTERTIRTY +:tORTAIRS +:to:to:to:to:to:to:to:to:to:to:to:to:tos: 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
0x00000001095c36afdispatchPreprocessedEventFromEventQueue + 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: 以 NSException 类型的未捕获异常终止

4

1 回答 1

0

2018-09-05 11:03:28.708661+0530 musicPlayer[25450:590989] -[musicPlayer.SecondViewController 更多:]:无法识别的选择器发送到实例 0x7fc1d4606d00

上面的消息意味着SecondViewController期望有方法被调用more:,但是当动作被触发并且这个类的实例试图找到该more:方法时,它无法识别这样的方法并且应用程序崩溃了。

我认为这里发生的事情是:您已将操作从 Xib/Storyboard 拖到您的 VC 类并命名为more:。在此之后,您手动将其重命名(不是 Refactor > Rename)为moreClicked:. 这样 IBAction 的SecondViewController仍然指向被调用的方法more:,但是你的类不再有这样的方法了。

所以基本上,你需要从你的 xib/storyboard 中删除已经存在的 IBAction 引用,并用新的方法重新连接它:moreClicked:,一切都应该正常工作。

于 2018-09-05T06:29:34.140 回答