添加ViewController时出现'unrecognized selector sent to instance'错误求助
Hey there, let's break down your crash issue and get your AR app back on track!
First, let's zero in on your error message:
Thread 1: "-[_0_2_2020_2.WelcomeViewController letsGo:]: unrecognized selector sent to instance 0x13ec05e00"
This is a classic mismatched IBAction connection problem. Here's exactly what's going wrong:
- In your Storyboard/XIB, the welcome button is linked to a method named
letsGo: - But in your
WelcomeViewControllercode, the actual IBAction you wrote is namedgotPressed(_:)
When the button is tapped, iOS tries to call a method that doesn't exist in your view controller, triggering this "unrecognized selector" crash.
- Open your project's Storyboard and locate the welcome button in
WelcomeViewController - Right-click the button to open its connection menu, or switch to the Connections Inspector (arrow icon in the right-side panel)
- Under the "Sent Events" section, find the
letsGo:connection and click the small "x" to delete it - Reconnect the button correctly: Hold down the
Ctrlkey, drag from the button directly to thegotPressed(_:)method in yourWelcomeViewControllercode, and confirm the connection
I spotted another critical issue in your ViewController class that will cause problems later (even after fixing the crash):
The application(_:didFinishLaunchingWithOptions:) method belongs to UIApplicationDelegate (usually in AppDelegate.swift or SceneDelegate.swift), not a view controller. Putting it in ViewController means it will never run, and it's invalid code structure.
Delete this entire block from your ViewController:
//delay app launch to show splash screen func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Thread.sleep(forTimeInterval: 3.0) // Override point for customization after application launch. return true } //end splash screen delay
If you want to add a launch screen delay, use the official Launch Screen setup in your project settings instead of blocking the main thread with Thread.sleep (this harms app performance and user experience).
After making these changes:
- Clean your build folder (go to
Product > Clean Build Folderin Xcode) - Restart Xcode to clear any cached connections
- Run your app again—tapping the welcome button should now smoothly navigate to your AR view controller without crashing
内容的提问来源于stack exchange,提问作者Tyler Kurtz

