首先,我为这个可能有点容易/愚蠢的问题道歉。 但是,我现在已经尝试调试此错误很长一段时间了。不幸的是没有运气,我最近开始在Xcode工作并使用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 :(得分:2)
最重要的错误信息是:
此类不是键值stateButtonPressed的键值编码兼容。
stateButtonPressed
。它很可能是Interface Builder中的死连接。答案 1 :(得分:1)
另一种查看您是否与对象有任何意外连接的方法是查看您在主故事板中创建的每个对象。选择您构建的对象后,查看最右侧的面板,单击带有右箭头符号的圆圈(最后一个),您将看到&#34;引用Outlets&#34;。确保它只列出了所需的View Controller连接 - 对于基本应用程序,每个对象应该只有一个连接。
答案 2 :(得分:0)
如果你在输出中查看这一行:
2017-03-01 18:03:39.849 myPillsNoob [969:17069] ***终止app到期 未捕获的异常'NSUnknownKeyException',原因: “[ setValue:forUndefinedKey:]:此类不是键值 符合编码的关键状态stateButtonPressed。'
它告诉您,您的应用中的某些内容正在尝试在stateButtonPressed
课程中设置属性/变量/键myPillsNoob.ViewController
,但key
不存在。
最常见的原因是您在某些时候在Interface Builder中添加了IBOutlet引用,然后在代码中删除了IBOutlet
行。
编辑:一个常见的原因......
Ctrl +从UIButton拖动到代码
输入“stateButtonPressed”
请注意,我忘记将“连接”下拉列表从“插座”更改为“操作”
删除刚刚添加的@IBOutlet weak var stateButtonPressed: UIButton!
行
Ctrl +再次从按钮拖动,这次选择动作以自动生成我的IBAction功能
而且......我现在有一个按钮,想要一个不再存在的IBOutlet。
至少,这就是我所做的:)