ios - Could not cast value of type exception in UIPickerView -
i implementing uipickerview
populated parse.com objects. want show selected row string pickerview
in textfield
.
at execution, when user selects row textfield
shows text when trying pass textfield
text viewcontroller
, app launches exception:
could not cast value of type
this code:
class citaservicio3: uiviewcontroller,uitextfielddelegate,uipickerviewdatasource,uipickerviewdelegate { var receivednombre: string = "" var receivedemail: string = "" var receivedcelular: string = "" var receivedtelefono: string = "" var receivedfecha: string = "" var receivedhora: string = "" @iboutlet weak var vehiculopickerview: uipickerview! @iboutlet var vehiculotextfield:uitextfield! var pickerstring:nsmutablearray = [] override func viewdidload() { super.viewdidload() print("receivednombre=",receivednombre) print("receivedemail=",receivedemail) print("receivedcelular=",receivedcelular) print("receivedtelefono=",receivedtelefono) print("receivedfecha=",receivedfecha) print("receivedhora=",receivedhora) let query = pfquery(classname: "autos") query.findobjectsinbackgroundwithblock({ (objects : [pfobject]?, error: nserror?) -> void in if error == nil { object in objects! { print (object["modelo"]) self.pickerstring.addobject(object["modelo"] as! string) } } self.vehiculopickerview.reloadallcomponents() }) } func numberofcomponentsinpickerview(pickerview: uipickerview) -> int { return 1 } // returns # of rows in each component.. func pickerview(pickerview: uipickerview, numberofrowsincomponent component: int) -> int { return self.pickerstring.count } func pickerview(pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { return self.pickerstring[row] as? string } func pickerview(pickerview: uipickerview, didselectrow row: int, incomponent component: int) { self.vehiculotextfield.text = self.pickerstring[row] as? string } @ibaction func continuarbutton(sender: anyobject) { let vehiculocita = vehiculotextfield.text if (vehiculocita!.isempty ){ let myalert = uialertcontroller(title: "faltan datos", message: "su vehiculo es obligatorio", preferredstyle: uialertcontrollerstyle.alert) let okalert = uialertaction(title: "reintentar", style: uialertactionstyle.default, handler: nil) myalert.addaction(okalert) self.presentviewcontroller(myalert, animated: true, completion: nil) return } [self .performseguewithidentifier("cita3a4", sender: self)] } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject!) { print (segue.identifier) print (vehiculotextfield.text) if "cita3a4" == segue.identifier { let cita4: citaservicio4 = segue.destinationviewcontroller as! citaservicio4 cita4.receivednombre = receivednombre cita4.receivedemail = receivedemail cita4.receivedcelular = receivedcelular cita4.receivedtelefono = receivedtelefono cita4.receivedfecha = receivedfecha cita4.receivedvehiculo = vehiculotextfield.text! } }
what wrong in code?
you saying:
let cita4: citaservicio4 = segue.destinationviewcontroller as! citaservicio4
but destination view controller of segue not citaservicio4. (it is, in fact, citaservicio3.) therefore crash @ runtime when forced cast turns out impossible.
it seems structure of things in storyboard not think is. recheck segues, esp. storyboard identifiers , class of view controller lead.
Comments
Post a Comment