1

I couldn't create a pagination technic like viewDidLoad: loadPosts() - scrollViewDidScroll: loadMore() for our feeds using Firebase IOS SDK in best logic way. It's easy to me .limit() query on Parse mBaaaS. But I didn't do it with Firebase, there is big problem like UIRefreshControl() comes crash, not loading while scrolling etc.

And then I find that real time updates nice thing for my feeds page, but when I add new post using Firebase Dashboard (I did it for testing like another user adding new post on "posts" root node) tableView scrollUp a little bit by itself. This is bad, if I read something on feed page why app takes me to different place from before.

Is there any way to prevent this scrollUp by Firebase observeEventType(.Value..?

Here'is my viewDidLoad: loadPosts() func:

    let query = DataService.ds.REF_POSTS.queryOrderedByChild("timestamp")

    query.observeEventType(.Value, withBlock: { snapshot in

        if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {

            self.posts = []
            for snap in snapshots {
                if let postDict = snap.value as? Dictionary<String, AnyObject> {
                    let post = Post(postKey: snap.key, dictionary: postDict)
                    self.posts.append(post)
                }
            }

            self.posts = self.posts.reverse()
            self.tableView.reloadData()

            self.loadingIndicator.stopAnimating()

        }
    })
iamburak
  • 3,508
  • 4
  • 34
  • 65
  • Are you keeping track of which posts are currently being displayed? i.e. post_id_25 is the first post being displayed in the tableView? If not, you should be so when you reloadData() you can position the posts in your tableView like they were before the reload. – Jay Apr 04 '16 at 21:51
  • Thanks for reply, I'm new ios development. How can I keep currently being displayed cell in tableView? Is there any override function to do it? I don't now how position specific cell using scroll or different way. If you can explain more, It can help me. – iamburak Apr 04 '16 at 22:00
  • There are a number of questions about that topic available but here's one that helped me [Setting scroll position in UITableView](http://stackoverflow.com/questions/413055/setting-scroll-position-in-uitableview). It's ObjC but gives you the basic idea. – Jay Apr 04 '16 at 22:56
  • I couldn't make a possible solution for this problem. How can I create firebase pagination in a logic way using firebase for feed page. (with pull to refresh and loadMore() after scrolling contentOffset) – iamburak Apr 06 '16 at 08:27

0 Answers0