Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift reload tableview without interrupting a single cell

I have an active observer that will refresh the tableview when new data comes in.

ref.child(live_mode).queryOrderedByKey().queryLimited(toLast: 200).observe(.childAdded, with: {snapshot in
            
            self.posts.insert(PostFeed(uid: uid , profile_image_url: profile_image_url, profile_name: profile_name, post_id: post_id, post_title: post_title, post_text: post_text, post_type: post_type, youtube_video_url: youtube_video_url, youtube_video_id: youtube_video_id, youtube_image_url: youtube_image_url, time_stamp: time_stamp, like_count: "0"), at: 0)

            DispatchQueue.main.async {
                 self.tableView.reloadData()
               }
        })

I would like the table view to be un-interupted or unrefreshed based on one saved indexPath. Meaning I would like the tableView to be reloaded but I dont want an individual cell reloaded since its playing a video.

savedIndex = indexPath // cell to not be reloaded since playing video

What is the best way to reload the tableView when new data comes in but without interrupting the saved index cell that would be showing a video?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the API to insert single rows

ref.child(live_mode).queryOrderedByKey().queryLimited(toLast: 200).observe(.childAdded, with: {snapshot in
        
    self.posts.insert(PostFeed(uid: uid , profile_image_url: profile_image_url, profile_name: profile_name, post_id: post_id, post_title: post_title, post_text: post_text, post_type: post_type, youtube_video_url: youtube_video_url, youtube_video_id: youtube_video_id, youtube_image_url: youtube_image_url, time_stamp: time_stamp, like_count: "0"), at: 0)
    DispatchQueue.main.async {
        self.tableView.insertRows(at: [IndexPath(row: O, section: 0)], with: .automatic)
    }
})

The other cells are not affected, and you get a nice animation for free.

If the section is not 0, specify the proper section index.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading