Tuesday, June 30, 2026
HomeiOS Developmentios - Unrecognized selector despatched to class + uncaught exception of kind...

ios – Unrecognized selector despatched to class + uncaught exception of kind NSException / NSInvalidArgumentException

[ad_1]

I am nonetheless crashing my app with the UIBarButtonItem:
I’ve tried 3 a number of methods I discovered right here in earlier matters, and none of them have labored out. I am new to Swift and I actually do not know what might be inflicting the issue, earlier than it labored simply superb…

The three a number of methods I attempted, which 1 is the unique code:

1)
let btnDone = UIBarButtonItem(barButtonSystemItem: .achieved, goal: MyViewController.self, motion: #selector(onBtnDoneTap))

@objc non-public func onBtnDoneTap() { code to be executed on faucet... }

2)
let btnDone = UIBarButtonItem(barButtonSystemItem: .achieved, goal: MyViewController.self, motion: #selector(onBtnDoneTap(sender:)))

@objc non-public func onBtnDoneTap(sender: UIBarButtonItem) { code to be executed on faucet... }

3)
let btnDone = UIBarButtonItem(barButtonSystemItem: .achieved, goal: MyViewController.self, motion: #selector(onBtnDoneTap(_:)))

@objc non-public func onBtnDoneTap(_ sender: UIBarButtonItem) { code to be executed on faucet... }

All crashed on the next line:

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(appDelegateClass))

Thread 1: “+[App.MyViewController onBtnDoneTap]: unrecognized selector despatched to class 0x1051c38b0”

With the next errors within the output window:

[13122:7952368] *** Terminating app resulting from uncaught exception 'NSInvalidArgumentException', purpose: '+[App.MyViewController onBtnDoneTap]: unrecognized selector despatched to class 0x1051c38b0'

libc++abi: terminating with uncaught exception of kind NSException dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

*** Terminating app resulting from uncaught exception 'NSInvalidArgumentException', purpose: '+[App.MyViewController onBtnDoneTap]: unrecognized selector despatched to class 0x1051c38b0' terminating with uncaught exception of kind NSException (lldb)

Thanks to your assist!

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments