gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:13:12 28 4
gpt4 key购买 nike

我正在阅读教程,每次单击按钮时,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(活动)>”,
    “”,
    “”,
    “”,
    “”,
    “”,
    “”,
    “”,
    ”


将尝试通过打破约束来恢复


在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 / data / Containers / Shared / 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'而终止应用程序,原因:'试图插入非属性列表对象;层=>用于密钥myName'
*首先抛出调用堆栈:

    0 CoreFoundation 0x0000000103725b0b异常预处理+ 171
    1 libobjc.A.dylib 0x000000010318a141 objc_exception_throw + 48
    2 CoreFoundation 0x000000010378e625 + [NSException提高:格式:] + 197
    3 CoreFoundation 0x0000000103678729 _CFPrefsValidateValueForKey + 249
    4 CoreFoundation 0x00000001036e5afc-[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 572
    5 CoreFoundation 0x000000010378fdaa-[CFPrefsPlistSource已锁定_设置值:forKeys:计数:] + 794
    6 CoreFoundation 0x000000010374cc58-[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 264
    7 CoreFoundation 0x0000000103678620-[CFPrefsSource setValues:forKeys:count:] + 32
    8 CoreFoundation 0x0000000103786af6-[CFPrefsSearchListSource已锁定_设置值:forKeys:计数:] + 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 Foundation 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图形服务0x0000000107d05a24 GSEventRunModal + 62
    34 UIKit 0x0000000103b49134 UIApplicationMain + 159
    35 asd 0x0000000102bb1927主+ 55
    36 libdyld.dylib 0x0000000106d9a65d开始+ 1

libc ++ abi.dylib:以NSException类型的未捕获异常终止

最佳答案

您的代码的严重错误在这里:

@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”而终止应用程序,原因:“试图插入非属性列表对象;层=>用于密钥myName'


就是说您的代码正在尝试为键 myName设置无效的值。

有关约束的消息表明您的代码和情节提要设置可能需要修复,但这不是崩溃的原因。

关于ios - Swift:类AppDelegate中的线程1信号SIGABRT:UIResponder,UIApplicationDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45779155/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com