[英]signal sigabrt delegate -> AppDelegate.swift
首先,對於這個可能有些簡單/討厭的問題,我深表歉意。 但是,我已經嘗試調試此錯誤已有相當長的時間了。 不幸的是,沒有運氣,我最近開始在Xcode中工作並使用Swift。
我一直在關注在線課程Udemy的教程。 但是,插入代碼后,我不斷收到此錯誤:
Thread1: Signal SIGABRT
不知道會是什么。 我一直在看谷歌https://teamtreehouse.com/community/error-message-thread-1-signal-sigabrt-in-class-appdelegate
但這並不能解決我的問題:(
另外,很難理解到底發生了什么,因此我無法通過Google找到一個好的解決方案。 也許你可以幫我。
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
我按運行后,打印錯誤的屏幕。 +輸出,對不起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)
最重要的錯誤信息是:
此類與鍵stateButtonPressed的鍵值編碼不兼容。
stateButtonPressed
。 這很可能是Interface Builder中的死連接。 另一種查看對象是否有意外連接的方法是查看在主故事板上創建的每個對象。 選擇構建的對象后,查看最右邊的面板,單擊帶有右箭頭符號的圓圈(最后一個),您將看到“參考插座”。 確保它僅列出了所需的與View Controller的連接-對於基本應用程序,每個對象只能是一個連接。
如果在輸出中查看此行:
2017-03-01 18:03:39.849 myPillsNoob [969:17069] ***由於未捕獲的異常'NSUnknownKeyException'而終止應用程序,原因:'[setValue:forUndefinedKey:]:此類不符合鍵stateButtonPressed。”
它告訴您應用程序中的某些內容正在嘗試設置myPillsNoob.ViewController
類中的屬性/變量/鍵stateButtonPressed
,但是該key
不存在。
最常見的原因是您有時在Interface Builder中添加了IBOutlet引用,然后在代碼中刪除了該IBOutlet
行。
編輯:一個常見的原因...
Ctrl +從UIButton拖動到代碼中
鍵入“ stateButtonPressed”
請注意,我忘記將“連接”下拉列表從“插座”更改為“操作”
刪除@IBOutlet weak var stateButtonPressed: UIButton!
剛剛添加的行
再次從按鈕Ctrl + Drag拖動,這次選擇Action以自動生成我的IBAction函數
還有……我現在有一個按鈕,想要一個不再存在的IBOutlet。
至少,我就是這么做的:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.