/ / Swift: EXC_BAD_INSTRUCTION (codice = EXC_I386_INVOP, sottocodice = 0x0) - xcode, swift

Swift: EXC_BAD_INSTRUCTION (codice = EXC_I386_INVOP, sottocodice = 0x0) - xcode, swift

Ciao, sono nuovo di zecca e ho bisogno di aiuto

Ogni volta che eseguo il mio codice, la mia app si arresta in modo anomalo e invia un "errore sopra riportato"

Qualcuno può dirmi cosa devo fare o cosa devo sostituire nel mio codice?

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{


@IBOutlet weak var picker: UIPickerView!
var employeeNames = ["John","Jane","Jack","James"]


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


self.picker.delegate = self
self.picker.dataSource = self
}

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return employeeNames.count
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return employeeNames [row]
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(employeeNames[row])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

risposte:

1 per risposta № 1

Il tuo codice è assolutamente valido, quindi l'unicol'alternativa è che non hai agganciato la tua presa pickerView.Ctrl fai clic sulla visualizzazione del raccoglitore nello storyboard e verifica se il tuo "raccoglitore" di uscita si presenta. Se non lo fa, trascinare il cursore dal pickerView alla presa per agganciarlo su.