ios - Tableview Loading like Instagram, Facebook or any app -


i have xcode project loads data , puts them in arrays sorted through , placed on table. of when go table in viewdidload() part, have function gather of data need. stop app crashing loads limit of 30. my current problem once user scrolls through 30 items, want 30 more loaded beneath 30 (standard scrolling). way can think doing reloading whole table not smart.

i want standard scrolling feature see in apps instagram, facebook, or internet app loads data on tableview while user scrolling down. below have copied code use gather initial data:

func findanimalusers() {     //step 1: find users     let animalquery = pfquery(classname: "animals") //choosing class     animalquery.wherekey("dog", equalto: animaltype.text!) //getting users animal type user types     animalquery.limit = 30 //number of users intitally showing     animalquery.findobjectsinbackground (block: { (objects, error) -> void in         if error == nil { //if no error              //clean             self.animalarray.removeall(keepingcapacity: false)              //step 2: find related objects depending on query setting             object in objects! {                 self.animalarray.append(object.value(forkey: "user") as! string) //objectid of related users             }              //step 3: find users             let query = pfuser.query()             query?.wherekey("objectid", containedin: self.animalarray) //finding users             query?.adddescendingorder("createdat") //how order users             query?.findobjectsinbackground(block: { (objects, error) -> void in                 if error == nil {                      //clean                     self.usernamearray.removeall(keepingcapacity: false)                                                                                self.profilephotoarray.removeall(keepingcapacity: false)                     self.objectidarray.removeall(keepingcapacity: false)                      //find related objects depending on query setting                     object in objects! {                         self.usernamearray.append(object.object(forkey: "username") as! string)                         self.profilephotoarray.append(object.object(forkey: "profilephoto") as! pffile)                         self.objectidarray.append(object.objectid!)                      }                 } else {                     print(error)                 }             })         } else {             print(error)         }     }) } 

i have added code of how table uses information:

override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     //define cell     let cell = tableview.dequeuereusablecell(withidentifier: "cell") as! animalscell      //step 1: connect data server objects     cell.usernamelabel.text = usernamearray[indexpath.row]     cell.objectid = objectidarray[indexpath.row]     profilephotoarray[indexpath.row].getdatainbackground (block: { (data, error) in         if error == nil {             cell.profilephoto.image = uiimage(data: data!)                         } else {             print(error)         }                 }) 

so when view controller comes in viewdidload(), have findanimalusers() in start initial load. how can load next 30 while user scrolls down?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -