【发布时间】:2017-09-17 06:03:09
【问题描述】:
我是一名新的 Swift 程序员。我正在使用 TableViewController + NavigationController 构建我的第一个应用程序。
在我的应用中,我可以看到:
如果我点击加号按钮,我可以看到这个视图:
然后我编译所有字段,然后单击“确定”按钮。但我有这个错误:
2017-04-20 16:23:48.158 ArduinoHomeKit_bis[3238:795882] -[LuciKit id]:无法识别的选择器发送到实例 0x61000026a700 2017-04-20 16:23:48.162 ArduinoHomeKit_bis[3238:795882] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[LuciKit id]:无法识别的选择器发送到实例 0x61000026a700” *** 首先抛出调用堆栈: ( 0 核心基础 0x0000000107745b0b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00000001045c0141 objc_exception_throw + 48 2核心基础0x00000001077b5134-[NSObject(NSObject)不识别选择器:]+132 3 核心基础 0x00000001076cc840 ___forwarding___ + 1024 4 核心基础 0x00000001076cc3b8 _CF_forwarding_prep_0 + 120 5 ArduinoHomeKit_bis 0x0000000103fc0603 _TFC18ArduinoHomeKit_bis28ListaLuciTableViewController14tornaAllaListafCSo17UIStoryboardSegueT_ + 435 6 ArduinoHomeKit_bis 0x0000000103fc098a _TToFC18ArduinoHomeKit_bis28ListaLuciTableViewController14tornaAllaListafCSo17UIStoryboardSegueT_ + 58 7 UIKit 0x0000000105903bbf-[UIStoryboardUnwindSegueTemplate _performWithDestinationViewController:sender:] + 214 8 UIKit 0x0000000105903ab6-[UIStoryboardUnwindSegueTemplate _perform:] + 83 9 UIKit 0x000000010566ea1f-[UIStoryboardSegueTemplate 执行:] + 157 10 UIKit 0x0000000104ea8d22-[UIApplication sendAction:to:from:forEvent:] + 83 11 UIKit 0x00000001052e35c7-[UIBarButtonItem(UIInternal)_sendAction:withEvent:] + 149 12 UIKit 0x0000000104ea8d22-[UIApplication sendAction:to:from:forEvent:] + 83 13 UIKit 0x000000010502d25c-[UIControl sendAction:to:forEvent:] + 67 14 UIKit 0x000000010502d577-[UIControl_sendActionsForEvents:withEvent:] + 450 15 UIKit 0x000000010502d6eb-[UIControl_sendActionsForEvents:withEvent:] + 822 16 UIKit 0x000000010502c4b2-[UIControl touchesEnded:withEvent:] + 618 17 UIKit 0x0000000104f1649a-[UIWindow_sendTouchesForEvent:] + 2707 18 UIKit 0x0000000104f17bb0 -[UIWindow 发送事件:] + 4114 19 UIKit 0x0000000104ec47b0-[UIApplication sendEvent:] + 352 20 UIKit 0x00000001056a7adc __dispatchPreprocessedEventFromEventQueue + 2926 21 UIKit 0x000000010569fa3a __handleEventQueue + 1122 22 核心基础 0x00000001076ebc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 23 核心基础 0x00000001076d10cf __CFRunLoopDoSources0 + 527 24 核心基础 0x00000001076d05ff __CFRunLoopRun + 911 25 核心基础 0x00000001076d0016 CFRunLoopRunSpecific + 406 26 图形服务 0x00000001096fca24 GSEventRunModal + 62 27 UIKit 0x0000000104ea70d4 UIApplicationMain + 159 28 ArduinoHomeKit_bis 0x0000000103fc3ce7 主要 + 55 29 libdyld.dylib 0x00000001086e565d 开始 + 1 30 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)点击确定后,这是我尝试执行的代码:
@IBAction func tornaAllaLista(_ segue: UIStoryboardSegue){
do {
var vistaDettaglio: AggiungiLuceViewController = segue.source as! AggiungiLuceViewController
if(vistaDettaglio.nuovaLuce != nil && vistaDettaglio.nuovaLuce?.id == 0){
self.listaLuci.append(vistaDettaglio.nuovaLuce!)
self.tabella.reloadData()
}else{
}
} catch let errore {
print("[CDC] problema tornaAllaLista")
print(" Stampo l'errore: \n \(errore) \n")
}
}
编辑 这是我单击“确定”按钮时执行的代码:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//se il pulsante cliccato è diverso da OK torno indietro
if sender as? NSObject != self.buttonOK{
return
}
let nomeLuce = self.textNomeLuce.text!
let pinArduino = Int16(self.textPinArduino.text!)
let tipoLuce = self.textTipoLuce.text!
if(nomeLuce.characters.count>0){
//ho inserito almeno un carattere
LuciKitCoreDataController.shared.addLuce(descrizione: nomeLuce, pin_arduino: Int(pinArduino!))
self.nuovaLuce = LuciKit()
self.nuovaLuce?.descrizione = nomeLuce
self.nuovaLuce?.pin_arduino = pinArduino!
self.nuovaLuce?.id = 3
}else{
let alert = UIAlertController(title:"Attenzione", message: "Inserire un nome per la Luce", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated:true, completion: nil)
}
}
如果我尝试执行这行代码:
self.nuovaLuce?.descrizione = nomeLuce
我有一个错误
【问题讨论】:
-
发送到实例的无法识别的选择器意味着您尝试调用的函数不存在或不被识别。可能是您没有将 @IBAction 连接到情节提要中的按钮。