Swift:类AppDelegate中的线程1信号SIGABRT:UIResponder,UIApplicationDelegate

时间:2017-08-20 06:31:55

标签: ios swift xcode iboutlet

我正在按照教程进行操作,每次单击按钮时,我都会在AppDelegate.swift中收到错误,该错误表示主题1信号 SIGABRT

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { //Thread 1 signal SIGABRT

这是我的故事板的截图。 enter image description here

我看了一遍,一些答案引用的IBOutlet连接并不存在,但正如您在屏幕截图中看到的,我的所有连接都很好看,所以我不知道是什么问题是。

这是我的viewController.swift代码: 导入UIKit

类ViewController:UIViewController {

@IBOutlet weak var input: UITextField!
@IBOutlet weak var label: UILabel!

@IBAction func button(_ sender: UIButton) {
    label.text = input.text
    UserDefaults.standard.set(input, forKey: "myName")
    input.text = " "
}

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func viewDidAppear(_ animated: Bool) {
    if let x = UserDefaults.standard.object(forKey: "myName") as? String{
      label.text = x
    }
}

}

这是我点击按钮时收到的完整错误消息: 2017-08-20 23:29:09.155350 + 0800 asd [2297:997880] [LayoutConstraints]无法同时满足约束条件。     可能至少以下列表中的一个约束是您不想要的约束。     试试这个:         (1)看看每个约束,并试图找出你不期望的;         (2)找到添加了不需要的约束或约束的代码并修复它。 (     "< _UILayoutSupportConstraint:0x608000284d30 _UILayoutGuide:0x7fc28340be50.height == 20(有效)>",     "< _UILayoutSupportConstraint:0x608000283980 V:| - (0) - [_ UILayoutGuide:0x7fc28340be50](有效,姓名:' |':UIView:0x7fc28340b780)>",     "< _UILayoutSupportConstraint:0x608000284dd0 _UILayoutGuide:0x7fc28340c420.height == 0(有效)>",     "< _UILayoutSupportConstraint:0x608000284d80 _UILayoutGuide:0x7fc28340c420.bottom == UIView:0x7fc28340b780.bottom(active)>",     "&#34 ;,     "&#34 ;,     "&#34 ;,     "&#34 ;,     "&#34 ;,     "&#34 ;,     "&#34 ;,     "" )

将尝试通过违反约束来恢复

在UIViewAlertForUnsatisfiableConstraints处创建一个符号断点,以便在调试器中捕获它。 在列出的UIView上的UIConstraintBasedLayoutDebugging类别中的方法也可能有所帮助。 2017-08-20 23:29:11.137163 + 0800 asd [2297:997880] [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器是/ Users / Myeongjeon / Library / Developer / CoreSimulator / Devices / 200D40A8-EFD4 -4FE9-8E13-37C2E7D86BA6 /数据/容器/共享/ SystemGroup / systemgroup.com.apple.configurationprofiles 2017-08-20 23:29:11.137610 + 0800 asd [2297:997880] [MC]从私人有效用户设置中读取。 2017-08-20 23:29:15.719443 + 0800 asd [2297:997880] [用户默认值]尝试设置非属性列表对象; layer =>作为关键myName的NSUserDefaults / CFPreferences值 2017-08-20 23:29:15.723 asd [2297:997880] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:'尝试插入非属性列表对象; layer =>关键的myName' * 第一次抛出调用堆栈: (     0 CoreFoundation 0x0000000103725b0b exceptionPreprocess + 171     1 libobjc.A.dylib 0x000000010318a141 objc_exception_throw + 48     2 CoreFoundation 0x000000010378e625 + [NSException raise:format:] + 197     3 CoreFoundation 0x0000000103678729 _CFPrefsValidateValueForKey + 249     4 CoreFoundation 0x00000001036e5afc - [CFPrefsPlistSource sendMessageSettingValue:forKey:] + 572     5 CoreFoundation 0x000000010378fdaa - [CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 794     6 CoreFoundation 0x000000010374cc58 - [CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264     7 CoreFoundation 0x0000000103678620 - [CFPrefsSource setValues:forKeys:count:] + 32     8 CoreFoundation 0x0000000103786af6 - [CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 454     9 CoreFoundation 0x000000010374cc58 - [CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264     10 CoreFoundation 0x0000000103678620 - [CFPrefsSource setValues:forKeys:count:] + 32     11 CoreFoundation 0x00000001036bbfe9 - [CFPrefsSource setValue:forKey:] + 57     12 CoreFoundation 0x0000000103788a4f __108 - [_ CFXPreferences(SearchListAdditions)withSearchListForIdentifier:container:cloudConfigurationURL:perform:] _ block_invoke + 319     13 CoreFoundation 0x000000010378824d normalizeQuintuplet + 317     14 CoreFoundation 0x0000000103788909 - [_ CFXPreferences(SearchListAdditions)withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 105     15 CoreFoundation 0x0000000103772c15 - [_ CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 261     16 CoreFoundation 0x00000001036bbf34 _CFPreferencesSetAppValueWithContainer + 68     17基金会0x0000000102c89790 - [NSUserDefaults(NSUserDefaults)setObject:forKey:] + 55     18 asd 0x0000000102bafc51 TFC3asd14ViewController6buttonfCSo8UIButtonT + 1073     19 asd 0x0000000102baff6a TToFC3asd14ViewController6buttonfCSo8UIButtonT + 58     20 UIKit 0x0000000103b4ad82 - [UIApplication sendAction:to:from:forEvent:] + 83     21 UIKit 0x0000000103ccf5ac - [UIControl sendAction:to:forEvent:] + 67     22 UIKit 0x0000000103ccf8c7 - [UIControl _sendActionsForEvents:withEvent:] + 450     23 UIKit 0x0000000103cce802 - [UIControl touchesEnded:withEvent:] + 618     24 UIKit 0x0000000103bb87ea - [UIWindow _sendTouchesForEvent:] + 2707     25 UIKit 0x0000000103bb9f00 - [UIWindow sendEvent:] + 4114     26 UIKit 0x0000000103b66a84 - [UIApplication sendEvent:] + 352     27 UIKit 0x000000010434a5d4 __dispatchPreprocessedEventFromEventQueue + 2926     28 UIKit 0x0000000104342532 __handleEventQueue + 1122     29 CoreFoundation 0x00000001036cbc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17     30 CoreFoundation 0x00000001036b10cf __CFRunLoopDoSources0 + 527     31 CoreFoundation 0x00000001036b05ff __CFRunLoopRun + 911     32 CoreFoundation 0x00000001036b0016 CFRunLoopRunSpecific + 406     33 GraphicsServices 0x0000000107d05a24 GSEventRunModal + 62     34 UIKit 0x0000000103b49134 UIApplicationMain + 159     35 asd 0x0000000102bb1927 main + 55     36 libdyld.dylib 0x0000000106d9a65d start + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止

1 个答案:

答案 0 :(得分:0)

您的代码存在严重错误:

@IBOutlet weak var input: UITextField!

@IBAction func button(_ sender: UIButton) {
    label.text = input.text
    UserDefaults.standard.set(input, forKey: "myName")
    input.text = " "
}

您正尝试将input保存到标准UserDefaults,但inputUITextField。您无法将UITextField保存到UserDefaults

也许你想做这样的事情:

@IBAction func button(_ sender: UIButton) {
    label.text = input.text
    UserDefaults.standard.set(input.text ?? "", forKey: "myName")
    input.text = " "
}

调试输出中最重要的部分:

  

由于未捕获的异常终止应用' NSInvalidArgumentException',原因:'尝试插入非属性列表对象; layer =>关键字myName'

这是说您的代码正在尝试为密钥myName设置无效值。

有关约束的消息表明您的代码和故事板设置可能需要修复,但这不是导致崩溃的原因。