2017-02-28 85 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的連接 - 對於基本應用程序,它應該只是每個對象的一個​​連接。