请向我解释一下错误的性质:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序

问题描述 投票:-1回答:1

我正在Xcode版本11.4.1(11E503a)中创建我的第一个iOS应用程序。我正在使用Swift 5.1和Storyboard进行用户界面构建。我在一个视图应用程序中有五个TextField。用户应该在这些字段中输入数据,然后有一个发送按钮。当用户按下发送按钮时,字段中的数据应保存在词典中。我怀疑这是我做错事的部分。当我在模拟器中运行该程序时,我不确定错误的性质。以下是我在ViewController.swift中编写的代码

import UIKit

class ViewController: UIViewController {


@IBOutlet weak var SerialNumber: UITextField!

@IBOutlet weak var WastebinType: UITextField!

@IBOutlet weak var EnterStatus: UITextField!

@IBOutlet weak var ActionRequired: UITextField!

@IBOutlet weak var EnterZone: UITextField!

@IBOutlet weak var SendButton: UIButton!



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }


    @IBAction func SendTapped(_ sender: Any) {

        self.SaveFields()
        }

    func SaveFields(){   // This function is creating a dictionary of the data entered in the
        let SN = self.SerialNumber.text!            // text field
        let WT = self.WastebinType.text!
        let ER = self.EnterStatus.text!
        let AR = self.ActionRequired.text!
        let EZ = self.EnterZone.text!

        let dict = ["SN": SN, "WT": WT, "ER" : ER, "AR" : AR, "EZ" : EZ]

         print("/(dict)")
        }

}

以下是我在控制台中收到的错误消息:

2020-05-04 23:30:24.164409+0530 Garbage management[8811:544439] -[Garbage_management.ViewController SendTap:]: unrecognized selector sent to instance 0x7fc9e550a2c0
2020-05-04 23:30:24.179445+0530 Garbage management[8811:544439] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Garbage_management.ViewController SendTap:]: unrecognized selector sent to instance 0x7fc9e550a2c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23e39f0e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50ad79b2 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKitCore                           0x00007fff48bf7058 -[UIResponder doesNotRecognizeSelector:] + 302
    4   CoreFoundation                      0x00007fff23e3e90c ___forwarding___ + 1436
    5   CoreFoundation                      0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120
    6   UIKitCore                           0x00007fff48bc9235 -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKitCore                           0x00007fff4857a9d3 -[UIControl sendAction:to:forEvent:] + 223
    8   UIKitCore                           0x00007fff4857ad1b -[UIControl _sendActionsForEvents:withEvent:] + 396
    9   UIKitCore                           0x00007fff48579c8c -[UIControl touchesEnded:withEvent:] + 497
    10  UIKitCore                           0x00007fff48c04a70 -[UIWindow _sendTouchesForEvent:] + 1359
    11  UIKitCore                           0x00007fff48c067f5 -[UIWindow sendEvent:] + 4501
    12  UIKitCore                           0x00007fff48be0c39 -[UIApplication sendEvent:] + 356
    13  UIKitCore                           0x00007fff48c6b096 __dispatchPreprocessedEventFromEventQueue + 7328
    14  UIKitCore                           0x00007fff48c6e262 __handleEventQueueInternal + 6565
    15  UIKitCore                           0x00007fff48c64dcb __handleHIDEventFetcherDrain + 88
    16  CoreFoundation                      0x00007fff23d9deb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    17  CoreFoundation                      0x00007fff23d9dddc __CFRunLoopDoSource0 + 76
    18  CoreFoundation                      0x00007fff23d9d5b4 __CFRunLoopDoSources0 + 180
    19  CoreFoundation                      0x00007fff23d981ae __CFRunLoopRun + 974
    20  CoreFoundation                      0x00007fff23d97ac4 CFRunLoopRunSpecific + 404
    21  GraphicsServices                    0x00007fff38b2fc1a GSEventRunModal + 139
    22  UIKitCore                           0x00007fff48bc7f80 UIApplicationMain + 1605
    23  Garbage management                  0x000000010081d4ab main + 75
    24  libdyld.dylib                       0x00007fff519521fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

请帮助我理解此错误的性质,原因,解决方法。

ios swift viewcontroller iboutlet ibaction
1个回答
0
投票
@IBAction func SendTap(_ sender: Any) { self.SaveFields() }
© www.soinside.com 2019 - 2024. All rights reserved.