You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加ViewController时出现'unrecognized selector sent to instance'错误求助

Hey there, let's break down your crash issue and get your AR app back on track!

Root Cause of the Crash

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 WelcomeViewController code, the actual IBAction you wrote is named gotPressed(_:)

When the button is tapped, iOS tries to call a method that doesn't exist in your view controller, triggering this "unrecognized selector" crash.

Step-by-Step Fix for the IBAction Connection
  1. Open your project's Storyboard and locate the welcome button in WelcomeViewController
  2. Right-click the button to open its connection menu, or switch to the Connections Inspector (arrow icon in the right-side panel)
  3. Under the "Sent Events" section, find the letsGo: connection and click the small "x" to delete it
  4. Reconnect the button correctly: Hold down the Ctrl key, drag from the button directly to the gotPressed(_:) method in your WelcomeViewController code, and confirm the connection
Bonus: Fix an Incorrectly Placed Method

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).

Final Checks

After making these changes:

  • Clean your build folder (go to Product > Clean Build Folder in 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 13:27:33