ios - UIPickerView not showing the items -


i'm new in swift , i'm having troubles uipickerview. problem this:

when put items in picker , can choose. perfect don't know why when have 1 or 2 items don't show up, , have drag down times see it, , selected problem can't see :(

this code:

 class loginviewcontroller: uiviewcontroller,uipickerviewdatasource,uipickerviewdelegate{  @iboutlet var pickercol: uipickerview!  @iboutlet var labelcol: uilabel!  @iboutlet var textusuario: uitextfield! @iboutlet var textpassword: uitextfield!  let defaults = nsuserdefaults.standarduserdefaults() var picker = uipickerview() var numberofrows = 0 var namesarray = [string]() var idarray = [string]()     var numero = 0 var col : string = ""  override func viewdidload() {     pickercol.delegate = self     pickercol.datasource = self     parsejson()     super.viewdidload()        }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func parsejson(){     let parameters = [         "opcion": "listar_clientes",         "opci_codi" : "320"     ]      alamofire.request(.post, "http://desarrollo.educalinks.com.ec/mobile/main.php", parameters: parameters).responsejson { response in         let json1 = (response.result.value)         let result = json1!["result"] as! nsarray         let dataexample : nsdata = nskeyedarchiver.archiveddatawithrootobject(json1!)                     nslog("\(json1)")         nslog("\(result.count)")          in 0..<result.count{             let id = result[i]["id"] anyobject? as? int             let texto = result[i]["texto"] anyobject? as? string             var idcole = string(id)             self.namesarray.append(texto!)             self.idarray.append(idcole)             self.numberofrows = self.namesarray.count         }     } }  func numberofcomponentsinpickerview(pickerview: uipickerview) -> int{     return 1 }  func pickerview(pickerview: uipickerview, numberofrowsincomponent component: int) -> int{     return numberofrows }  func pickerview(pickerview: uipickerview, didselectrow row: int, incomponent component: int) {     labelcol.text=namesarray[row]     col = idarray[row] }  func pickerview(pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? {     if(namesarray.count != 0){         return namesarray[row]     }     return nil } 

i have been hours trying figure out why happening. before had picker 10 items , appears normally. 2 items no. appreciate help.

you should call pickercol.reloadallcomponents() after loop.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -