New Firebase retrieve data and put on the tableView (Swift)

后端 未结 2 968
太阳男子
太阳男子 2020-12-21 16:18

I made a simple social media with new Firebase, and I successfully save string with database and image with storage, but when it comes to retrieve data back to the tableView

2条回答
  •  醉梦人生
    2020-12-21 17:00

    The best practice here to to populate your tableView datasource (posts array) in your ViewDidLoad method. Then your tableView isn't trying to pull down data as it's refreshing.

    Also, since you are adding a .childAdded observer your app will be notified of any additions to firebase so when that happens, just add the new data to the posts array and refresh the tableView.

    There's no reason to continually pull data from Firebase as it's static until it changes. So load once and then wait for those changes - you may want to consider adding a .childChanged event (and removed) in case someone updates their pic for example.

    The Firechat app from Firebase is a great resource for understanding the best way to do this - if you follow that design pattern, you can avoid all networking issues and not have to worry about separate async calls.

    You can simply rely on Firebase to take care of itself.

    Edit... Well, while that is a Firechat link, the Obj-C code seems to be missing (thanks Firebase. ugh)

    So - in light of that, see my answer to this question as it has pattern for the code you need.

提交回复
热议问题