ios - libc++abi.dylib segue 错误,带有 NSException 类型的未捕获异常

标签 ios swift segue ibaction

我总共有三个 View Controller 。我在第一个 View Controller 上按下 Cntrl 并在右下角创建了第二个 View Controller 的 segue(尚未测试右上角的)。 Storyboard如下:

enter image description here

倒数第二个segue的描述是:

enter image description here

我已将 segue 放在第一个 View Controller 底部按钮的 IBAction 中。代码如下:

class ViewController: UIViewController {
    
    private lazy var app = ProjectApp()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    @IBAction func start_test(_ sender: Any) {
        if app.is_facial_analysis_completed() {
            DispatchQueue.main.async() {
                self.performSegue(withIdentifier: "home_to_quiz", sender: self)
            }
        } else {
            DispatchQueue.main.async() {
                self.performSegue(withIdentifier: "home_to_vision", sender: self)
            }
        }
    }

}

不太确定为什么会出现此错误:

libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这是测验 View 类的代码:

import UIKit

class QuizViewController: UIViewController {
    
    @IBOutlet var QuizView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

这是 quizViewController 的 View Controller 的屏幕截图:

enter image description here

完整错误

2019-11-20 02:02:34.141705+0400 XXX[47921:9768662] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fd98a7088b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key QuizView.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23baa1ee __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50864b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23ba9db9 -[NSException raise] + 9
    3   Foundation                          0x00007fff2563e130 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
    4   UIKitCore                           0x00007fff46f008e9 -[UIViewController setValue:forKey:] + 87
    5   UIKitCore                           0x00007fff471ec3fa -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x00007fff23b96212 -[NSArray makeObjectsPerformSelector:] + 242
    7   UIKitCore                           0x00007fff471e95a2 -[UINib instantiateWithOwner:options:] + 2190
    8   UIKitCore                           0x00007fff46f07b3b -[UIViewController _loadViewFromNibNamed:bundle:] + 395
    9   UIKitCore                           0x00007fff46f08660 -[UIViewController loadView] + 177
    10  UIKitCore                           0x00007fff46f0895f -[UIViewController loadViewIfRequired] + 172
    11  UIKitCore                           0x00007fff46f0910c -[UIViewController view] + 27
    12  UIKitCore                           0x00007fff46f2038e -[UIViewController _setPresentationController:] + 100
    13  UIKitCore                           0x00007fff46f18b9a -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1256
    14  UIKitCore                           0x00007fff46f1a602 -[UIViewController _presentViewController:withAnimationController:completion:] + 4325
    15  UIKitCore                           0x00007fff46f1ce7b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
    16  UIKitCore                           0x00007fff46f1d393 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
    17  UIKitCore                           0x00007fff46f1cdd9 -[UIViewController _presentViewController:animated:completion:] + 187
    18  UIKitCore                           0x00007fff46f1d040 -[UIViewController presentViewController:animated:completion:] + 150
    19  UIKitCore                           0x00007fff46f2131f -[UIViewController _showViewController:withAction:sender:] + 272
    20  UIKitCore                           0x00007fff476d69b7 __66-[UIStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 134
    21  UIKitCore                           0x00007fff476dc410 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276
    22  UIKitCore                           0x00007fff476dc2ce -[UIStoryboardSegueTemplate _perform:] + 82
    23  UIKitCore                           0x00007fff46f0be3b -[UIViewController performSegueWithIdentifier:sender:] + 99
    24  XXX                                 0x000000010d49b896 $s3XXX14ViewControllerC19pulse_permute_segueyyFyycfU_ + 118
    25  XXX                                 0x000000010d494c7d $sIeg_IeyB_TR + 45
    26  libdispatch.dylib                   0x000000010d954df8 _dispatch_call_block_and_release + 12
    27  libdispatch.dylib                   0x000000010d955d6c _dispatch_client_callout + 8
    28  libdispatch.dylib                   0x000000010d963e24 _dispatch_main_queue_callback_4CF + 1500
    29  CoreFoundation                      0x00007fff23b0ce49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    30  CoreFoundation                      0x00007fff23b07aa9 __CFRunLoopRun + 2329
    31  CoreFoundation                      0x00007fff23b06e66 CFRunLoopRunSpecific + 438
    32  GraphicsServices                    0x00007fff38346bb0 GSEventRunModal + 65
    33  UIKitCore                           0x00007fff47578dd0 UIApplicationMain + 1621
    34  XXX                                 0x000000010d4a724b main + 75
    35  libdyld.dylib                       0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

最佳答案

  1. 也许您需要添加 UINavigationViewController,例如 Initial View Controller

enter image description here

或者您需要覆盖此方法并在第二个 Controller 上设置一些必需的数据?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if (segue.identifier == "home_to_quiz") {
           let dectinationView = segue.destination as! YourCustomViewController
           dectinationView.dataContainer = self.dataContainer
        }
    }

加法

  1. 以下是一些可能出错的时刻:

    • UIViewController 的类必须是Inherit From Target

enter image description here

  • 尝试删除 Storyboard中的选择器 (home_to_quiz:)。您是否在 Controller 中实现了选择器方法?

关于ios - libc++abi.dylib segue 错误,带有 NSException 类型的未捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58887393/

相关文章:

ios - 为什么将对象追加到数组时会出现 nil 错误?

ios - 将触摸事件从 View 发送到 Controller

ios - performSegueWithIdentifier 不工作 - Swift

ios - 内容更改时 WKWebView 不调整大小

ios - 在 uiview 中显示引脚信息

ios - 对展开转场进行故障排除

ios - uicollectionview 继续详细查看 viewcontroller swift

android - 是否可以在 TFS2017 中构建 Android 和 iOS 应用程序?

ios - iOS 中的视频转换

iphone - 动态刷新 NSMUTABLEArray 的内容