我有一个活跃的观察者,它会在新数据进来时刷新表格视图。
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()
}
})
我希望基于一个保存的 indexPath 不中断或不刷新表视图。这意味着我希望重新加载 tableView 但我不希望在播放视频后重新加载单个单元格。
savedIndex = indexPath // cell to not be reloaded since playing video
当新数据进入时重新加载 tableView 的最佳方法是什么,但不会中断将显示视频的已保存索引单元格?
使用 API 插入单行
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)
}
})
其他单元格不受影响,免费获得漂亮的动画
如果部分不为 0,请指定正确的部分索引。