ios - How to populate table view with large data -
i'm trying populate table view large data. however, tableview can display 20 string objects. how display rest of data , update table view each time user scrolls end?
var people = [people]() let configuresession = urlsessionconfiguration.default let session = urlsession(configuration: configure) //setup api key... let apikey = "https://congress.api.sunlightfoundation.com/legislators?apikey=(//api key here...)" if error != nil{ print("error: \(error?.localizeddescription)") return } else if let jsondata = data { do{ let parsedjson = try jsonserialization.jsonobject(with: jsondata, options: []) as! [string: anyobject] guard let results = parsedjson["results"] as? [[string: anyobject]] else {return} result in results{ let name = myclass() name.firstname = result["first_name"] as! string self.people.append(name) } dispatchqueue.main.async { //reload data self.table.reloaddata() } } catch let error nserror{ print(error) } } }).resume() } } func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return people.count } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "cell") cell.textlabel?.text = people[indexpath.row] //only displays 20... need display more! return cell! } func tableview(_ tableview: uitableview, willdisplay cell: uitableviewcell, forrowat indexpath: indexpath) { let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath) //code display rest of data goes here? }
make sure return correct value in numberofrowsinsection
method:
func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return mylargedata.count }
with provided mylargedata
array there should 30 rows in tableview
Comments
Post a Comment