2017-02-28 88 views
2

首先,我很抱歉这可能有点简单/ noobish的问题。 但是,我一直在试图调试这个错误很长一段时间了。不幸的是,我最近开始使用Xcode并使用Swift。信号sigabrt委托 - > AppDelegate.swift

我一直在关注在线课程Udemy的教程。 然而,在插入代码之后,我不断收到此错误:

Thread1: Signal SIGABRT 

不知道什么是可能。我一直在寻找对谷歌 https://teamtreehouse.com/community/error-message-thread-1-signal-sigabrt-in-class-appdelegate

但这并没有解决我的问题:(

此外,它是很难理解究竟是什么发生的事情,所以我找不到通过谷歌一个很好的解决方案。也许你可以帮我出

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { 

    @IBOutlet weak var statePicker: UIPickerView! 
    @IBOutlet weak var statePickerBtn: UIButton! 

    let states = ["Alaska","Arkansas","Alabama","California","New York"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.statePicker.dataSource = self 
     statePicker.delegate = self 

     // 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. 
    } 

    @IBAction func stateBtnPressed(_ sender: AnyObject) { 
     statePickerBtn.isHidden = false 
    } 

    func numberOfComponents(in pickerView: UIPickerView) -> Int { 
     return 1 
    } 

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
     return states.count 
    } 

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
     return states[row] 
    } 

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
     statePickerBtn.setTitle(states[row], for: UIControlState.application) 
     statePicker.isHidden = true 
    } 

什么是我想要做的事:。 我有隐藏着一个选择器,当用户按下按钮,我希望它能够揭示选取器用户一旦该事件点击,他们会看到数组中的选择器,那么,你知道我的意思,但是当我构建它时,他模拟器仍然是白色的,Xcode提示我到AppDelegate.Swift出现这个特定的错误。

TNX

Print screen of the error after I pressed Run. + Output, sorry for messy prnt scrn :)

控制台输出:

2017-03-01 18:03:39.717795 myPillsNoob[969:17168] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2017-03-01 18:03:39.725996 myPillsNoob[969:17168] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2017-03-01 18:03:39.738908 myPillsNoob[969:17165] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0 
2017-03-01 18:03:39.760737 myPillsNoob[969:17069] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0 
2017-03-01 18:03:39.849 myPillsNoob[969:17069] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<myPillsNoob.ViewController 0x7fa24ce09160> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key stateButtonPressed.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001132e234b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000011038f21e objc_exception_throw + 48 
    2 CoreFoundation      0x00000001132e2299 -[NSException raise] + 9 
    3 Foundation       0x000000010fe9f2ff -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291 
    4 UIKit        0x00000001109f88c3 -[UIViewController setValue:forKey:] + 88 
    5 UIKit        0x0000000110c6cbe6 -[UIRuntimeOutletConnection connect] + 109 
    6 CoreFoundation      0x0000000113287590 -[NSArray makeObjectsPerformSelector:] + 256 
    7 UIKit        0x0000000110c6b56a -[UINib instantiateWithOwner:options:] + 1867 
    8 UIKit        0x00000001109feff5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386 
    9 UIKit        0x00000001109ff917 -[UIViewController loadView] + 177 
    10 UIKit        0x00000001109ffc4c -[UIViewController loadViewIfRequired] + 201 
    11 UIKit        0x0000000110a004a0 -[UIViewController view] + 27 
    12 UIKit        0x00000001108ca045 -[UIWindow addRootViewControllerViewIfPossible] + 71 
    13 UIKit        0x00000001108ca796 -[UIWindow _setHidden:forced:] + 293 
    14 UIKit        0x00000001108de0a9 -[UIWindow makeKeyAndVisible] + 42 
    15 UIKit        0x0000000110857259 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818 
    16 UIKit        0x000000011085d3b9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731 
    17 UIKit        0x000000011085a539 -[UIApplication workspaceDidEndTransaction:] + 188 
    18 FrontBoardServices     0x000000011477b76b __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 
    19 FrontBoardServices     0x000000011477b5e4 -[FBSSerialQueue _performNext] + 189 
    20 FrontBoardServices     0x000000011477b96d -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
    21 CoreFoundation      0x0000000113287311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    22 CoreFoundation      0x000000011326c59c __CFRunLoopDoSources0 + 556 
    23 CoreFoundation      0x000000011326ba86 __CFRunLoopRun + 918 
    24 CoreFoundation      0x000000011326b494 CFRunLoopRunSpecific + 420 
    25 UIKit        0x0000000110858db6 -[UIApplication _run] + 434 
    26 UIKit        0x000000011085ef34 UIApplicationMain + 159 
    27 myPillsNoob       0x000000010fdb071f main + 111 
    28 libdyld.dylib      0x0000000113fe568d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 
+0

还有什么更多 - 控制台或Xcode - 来帮助我们吗?这是一个非常普遍的错误。但是,错误的细节应该指向这个问题。 – dfd

+0

我在哪里可以找到你所需要的?控制台保持空着。我习惯在Visual Studio中编写软件,并在两天前开始使用Xcode。有点困惑 – Niklaus

+0

我写了VS约15年,直到2015年,所以我明白你的痛苦。 :-)我假设Xcode不会“停止”一行代码。 (如果是,请指出哪一行。)除此之外,还有两件事:(1)菜单选项查看|调试区域|激活控制台。 (2)直接点击左侧栏中的SIGABRT错误。 (你会看到一个非常混乱的转储,但它会有所帮助。) – dfd

回答

1

最显著的错误信息是:

this class is not key value coding-compliant for the key stateButtonPressed.

  • ⇧⌘F
  • 搜索stateButtonPressed。这很可能是Interface Builder中的死连接。
  • 删除连接。
+0

非常感谢!你可以告诉我这是可能的吗?我在课程中确实喜欢,将它拖入代码中。这怎么会出现问题呢?此外,我很抱歉无法给你一个+1,因为我没有所需的声望upvote :( – Niklaus

+1

也许你曾经有一个方法'stateButtonPressed'并在Interface Builder中建立了连接,然后你重命名了方法将视图控制器设置为'stateBtnPressed'。这打破了连接。 – vadian

+0

噢,你是对的!谢谢你清理我的脑袋! – Niklaus

0

如果你看一下该线路输出:

2017-03-01 18:03:39.849 myPillsNoob[969:17069] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key stateButtonPressed.'

它告诉你的东西在你的应用程序正试图设置你的myPillsNoob.ViewController类属性/变量/键stateButtonPressed,但key不在这里。

最常见的原因是您在某些时候在Interface Builder中添加了IBOutlet引用,然后在您的代码中删除了IBOutlet行。

编辑:一个常见原因...

  1. 按Ctrl +拖动从一个UIButton成代码

  2. 类型 “stateButtonPressed”

  3. 注意,我忘记连接下拉从 “出口” 到 “行动”

  4. 改变

    删除刚刚添加的@IBOutlet weak var stateButtonPressed: UIButton!

  5. Ctrl +拖动fr再次按下按钮,这次选择动作来自动生成我的IBAction功能

  6. 而且......我现在有一个按钮,希望IBOutlet不再存在。

至少,这就是我做什么:)

+0

我不记得我删除了任何IBOutlet,但是非常感谢你的解释,不幸的是我不能upvote你的答案因为我没有必要的声望 – Niklaus

+0

@尼克劳斯 - 我编辑了我的答案......并不是说这就是你所做的,但它可能会为你在未来避免头痛 – DonMag

+0

可能究竟发生了什么事! – Niklaus

1

另一种方法,如果你有你的对象的任何意外的连接是看每次在主要故事板创建的对象的。一旦你选择了你建立的对象,看看最右边的面板,用右箭头符号(最后一个)点击圆圈,你会看到“引用出口”。确保它仅列出您想要的View Controller的连接 - 对于基本应用程序,它应该只是每个对象的一个​​连接。