示例项目中的问题仅发生在最后两个单元格中。最后一个中的结果动画有点不同,但即使使用自动,结果也是一样。
func loadData(){
let userID = Auth.auth().currentUser!.uid
Database.database().reference().child("notification").child(userID).observe(.childAdded, with: { (snapshot) in
guard let dictionary = snapshot.value as? [String: Any] else { return }
let uid = dictionary["uid"] as? String
let postId = dictionary["postID"] as? String
Database.fetchUserWithUID(uid: uid!, completion: { (snapshot) in
Database.fetchPostWithUID(uid: userID, postId: postId!, completion: { (postShot) in
Database.fetchVideoPostWithUID(uid: userID, postId: postId!, completion: { (videoShot) in
let comment = notification(user: snapshot, post: postShot, videoPost: videoShot, dictionary: dictionary)
self.notifications.append(comment)
self.notificationTableView?.reloadData()
})
})
})
})
}
extension Database {
static func fetchUserWithUID(uid: String, completion: @escaping (userAccount) -> ()) {
Database.database().reference().child("user").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in
let user = userAccount(snapshot:snapshot)
completion(user)
})
}
static func fetchPostWithUID(uid: String, postId: String, completion: @escaping (Post) -> ()) {
Database.database().reference().child("post").child(uid).child(postId).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists() {
let post = Post(snapshot:snapshot)
completion(post)
}else{
// Not sure what to write here when snapshot is equal to nil
})
}
static func fetchVideoPostWithUID(uid: String, postId: String, completion: @escaping (videoPost) -> ()) {
Database.database().reference().child("videoPost").child(uid).child(postId).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists(){
let post = videoPost(snapshot:snapshot)
completion(post)
}else{
// Again not sure what to write here when snapshot is equal to nil
}
})
}
开始动画:https://i.stack.imgur.com/PcQty.png
最终结果:https://i.stack.imgur.com/uSljt.png
我创建了一个示例项目(插入新单元格):https://github.com/elanovasconcelos/TestTableAnimation
答案 0 :(得分:0)
我的主要问题是桌子需要一个页脚才能使动画看起来正确。我添加了一个比大单元格更大的单元,之后动画就可以了。