ios - 初学者 : Swift for iOS. 信号 SIGABRT

标签 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"
    }
}

当我运行此代码时,我在 lign class AppDelegate: UIResponder, UIApplicationDelegate { of AppDelegate.swift

处收到错误 signal SIGABRT

这是控制台的输出

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) 

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


我正在使用 Xcode 版本 7.2.1

最佳答案

仔细检查你的操作方法,

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

它可能没有连接到 Storyboard中的 View Controller 。

检查:

  1. 转到 main.storyboard 和

enter image description here

右键单击“先点击此处”按钮,然后您会看到黄色警告图标,这意味着它未连接到您的 setDefaultLabelText。使用助理编辑器连接它们。

关于ios - 初学者 : Swift for iOS. 信号 SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420911/

相关文章:

python - ipython-pylab 调试 : Can I stop the execution at a specific line and drop into the shell?

ios - 是否可以在 Xcode 中加载包含 swift 类的资源文件夹的内容?

ios - 通过 NSDictionary 将 NSUserDefaults standardUserDefaults 放入 TableView

ios - 在其图像上显示 UIBarButton 标题

ios - 试图将某些类型的用户路由到不同的主屏幕 Swift

ios - 使用 MKDirectionsRequest 和 MKMapView 没有显示路线,xcode 打印 'unexpected waypoint index'

swift - AzureAD b2c MSAL - token 响应缺少访问 token

javascript - 如何使用谷歌浏览器调试 Vue 应用程序

ios/uipickerview : How would I have a picker view for US states

debugging - Firefox SDK Extension Builder - 检查/调试面板的 html 和 dom