Reputation: 2159
I'm a new Swift programmer. I'm building my first app with TableViewController + NavigationController.
In my app, I can see this:
If I click on Plus button I can see this View:
Then I compile all field and then I click on OK button. But I have this error:
2017-04-20 16:23:48.158 ArduinoHomeKit_bis[3238:795882] -[LuciKit id]: unrecognized selector sent to instance 0x61000026a700 2017-04-20 16:23:48.162 ArduinoHomeKit_bis[3238:795882] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LuciKit id]: unrecognized selector sent to instance 0x61000026a700' *** First throw call stack: ( 0 CoreFoundation 0x0000000107745b0b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00000001045c0141 objc_exception_throw + 48 2 CoreFoundation 0x00000001077b5134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00000001076cc840 ___forwarding___ + 1024 4 CoreFoundation 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 perform:] + 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 sendEvent:] + 4114 19 UIKit 0x0000000104ec47b0 -[UIApplication sendEvent:] + 352 20 UIKit 0x00000001056a7adc __dispatchPreprocessedEventFromEventQueue + 2926 21 UIKit 0x000000010569fa3a __handleEventQueue + 1122 22 CoreFoundation 0x00000001076ebc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 23 CoreFoundation 0x00000001076d10cf __CFRunLoopDoSources0 + 527 24 CoreFoundation 0x00000001076d05ff __CFRunLoopRun + 911 25 CoreFoundation 0x00000001076d0016 CFRunLoopRunSpecific + 406 26 GraphicsServices 0x00000001096fca24 GSEventRunModal + 62 27 UIKit 0x0000000104ea70d4 UIApplicationMain + 159 28 ArduinoHomeKit_bis 0x0000000103fc3ce7 main + 55 29 libdyld.dylib 0x00000001086e565d start + 1 30 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
After click OK this is the code that I try to execute:
@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")
}
}
EDIT This is the code that I execute when I click on OK button:
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)
}
}
If I try to execute this line code:
self.nuovaLuce?.descrizione = nomeLuce
I have an error
Upvotes: 0
Views: 81
Reputation: 2044
Pretty sure that this is the offending line:
vistaDettaglio.nuovaLuce?.id == 0
Object stored under novaLuce
doesn't contain a method
called -id
, as it seems to be.
Upvotes: 0