ios - How to pass data from variable to an Array? -


in app load database guest's informations. after checked user profile, pass data using global variables , sender.

in tableview have display data variables... problem cannot put variables array, tried implement struct method, doesn't works.

// //  schedavolontario.swift //  amesci // //  created gianluca caliendo on 06/07/17. //  copyright © 2017 amesci. rights reserved. //  import uikit  class schedavolontario: uiviewcontroller, uitableviewdatasource, uitableviewdelegate {       var cognome : string?     var sede : string?     var progetto : string?     var datainizioservizio : string?     var datafineservizio : string?     var licenze : string?     var malattie : string?     var codvolontariostring : string?       struct nomestruct {         var nome : string?     }     struct cognomestruct {         var cognome : string?     }     struct sedestruct {         var sede : string?     }     struct progettostruct {         var progetto : string?     }     struct datainizioserviziostruct {         var datainizioservizio : string?     }     struct datafineserviziostruct {         var datafineservizio : string?     }     struct licenzestruct {         var licenze : string?     }     struct malattiestruct {         var malattie : string?     }     struct codvolontariostruct {         var codvolontariostring : string?     }       var list = [nomestruct.self, cognomestruct.self, sedestruct.self, progettostruct.self, datainizioserviziostruct.self, datafineserviziostruct.self, licenzestruct.self, malattiestruct.self, codvolontariostruct.self] [any]       func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {         return list.count     }       func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {         let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)          cell.textlabel?.text = list[indexpath.row] as? string          return cell     }       override var prefersstatusbarhidden : bool {         return true     }   } 

it didn't work because populate list of types, not values. should include reference tableview , reload everytime populate list. try this:

import uikit  class schedavolontario: uiviewcontroller, uitableviewdatasource, uitableviewdelegate {    var nome: string?   var cognome : string?   var sede : string?   var progetto : string?   var datainizioservizio : string?   var datafineservizio : string?   var licenze : string?   var malattie : string?   var codvolontariostring : string?    var guestinfolist: [string] = []    // connect outlet table view in storyboard   @iboutlet weak var guestinfotableview: uitableview!    override func viewdidload() {     super.viewdidload()      populateguestinfolist()     guestinfotableview.reloaddata()   }    func populateguestinfolist() {     if let nome = nome {       guestinfolist.append(nome)     }      if let cognome = cognome {       guestinfolist.append(cognome)     }      if let sede = sede {       guestinfolist.append(sede)     }      if let progetto = progetto {       guestinfolist.append(progetto)     }      if let datainizioservizio = datainizioservizio {       guestinfolist.append(datainizioservizio)     }      if let datafineservizio = datafineservizio {       guestinfolist.append(datafineservizio)     }      if let licenze = licenze {       guestinfolist.append(licenze)     }      if let malattie = malattie {       guestinfolist.append(malattie)     }      if let codvolontariostring = codvolontariostring {       guestinfolist.append(codvolontariostring)     }   }    func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {     return guestinfolist.count   }     func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)     cell.textlabel?.text = guestinfolist[indexpath.row]     return cell   } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -