初学者:适用于iOS的Swift。信号SIGABRT

时间:2017-07-31 16:23:03

标签: ios swift debugging

我正试图在此developer.apple tutorial之后在Swift中学习iOS应用程序开发,但我迷路了。我是一名经验丰富的程序员(没有任何GUI经验),但我认为我对Xcode界面感到困惑。

我正在尝试按照上面的教程

测试以下非常简单的应用程序
//
//  ViewController.swift
//  test
//
//  Created by Remi on 2017-07-29.
//  Copyright © 2017 Remi. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    //MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //MARK: Actions
    @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}

当我运行此代码时,我在AppDelegate.swift的signal SIGABRT class AppDelegate: UIResponder, UIApplicationDelegate {处收到错误2017-07-31 09:15:56.334 test[78397:35616616] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<test.ViewController 0x7fdf1bb0f770> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setDefaultLabelText.' *** First throw call stack: ( 0 CoreFoundation 0x000000010fd26e65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000111a66deb objc_exception_throw + 48 2 CoreFoundation 0x000000010fd26aa9 -[NSException raise] + 9 3 Foundation 0x00000001100ef9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x00000001106d2320 -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000110900f41 -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x000000010fc674a0 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit 0x00000001108ff924 -[UINib instantiateWithOwner:options:] + 1864 8 UIKit 0x00000001106d8eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x00000001106d9816 -[UIViewController loadView] + 178 10 UIKit 0x00000001106d9b74 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x00000001106da2e7 -[UIViewController view] + 27 12 UIKit 0x00000001105b0ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x00000001105b1199 -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x00000001105c2c2e -[UIWindow makeKeyAndVisible] + 42 15 UIKit 0x000000011053b663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 16 UIKit 0x0000000110541cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760 17 UIKit 0x000000011053ee7b -[UIApplication workspaceDidEndTransaction:] + 188 18 FrontBoardServices 0x00000001138fb754 -[FBSSerialQueue _performNext] + 192 19 FrontBoardServices 0x00000001138fbac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 20 CoreFoundation 0x000000010fc52a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 21 CoreFoundation 0x000000010fc4895c __CFRunLoopDoSources0 + 556 22 CoreFoundation 0x000000010fc47e13 __CFRunLoopRun + 867 23 CoreFoundation 0x000000010fc47828 CFRunLoopRunSpecific + 488 24 UIKit 0x000000011053e7cd -[UIApplication _run] + 402 25 UIKit 0x0000000110543610 UIApplicationMain + 171 26 test 0x000000010fb4846d main + 109 27 libdyld.dylib 0x000000011256f92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

这是控制台上的输出

k

你能帮我理解这里发生了什么吗?

我正在使用Xcode Version 7.2.1

3 个答案:

答案 0 :(得分:1)

您可能已在uistoryboard上删除了viewcontroller的类名。 请查看此图片以获取参考enter image description here

答案 1 :(得分:1)

仔细检查您的行动方法,

 @IBAction func setDefaultLabelText(sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }

它可能未连接到情节提要中的视图控制器。

检查:

  1. 转到main.storyboard和
  2. enter image description here

    右键单击第一个点击此处按钮,然后您会看到黄色警告图标,表示它未连接到您的setDefaultLabelText。使用Assistant Editor连接它们。

答案 2 :(得分:0)

我认为你删除了他们重新插入的东西。转到主故事板并右键单击视图控制器的黄色部分。如果有黄色危险符号则将其删除