1
使用swift3,我想允許用戶創建圖片或簡單文本帖子的帖子。我有一切工作正常,除了當我創建一個文本後,單元格中的UIImageView填充了TableViewCell中的空間。理想情況下,如果用戶創建一個文本文章,TableViewCell將只包含標題標籤的所有內容,但不包括UIImageView(見圖)。我怎麼去解決這個問題。使用swift3動態調整TableViewCell的大小,使其不帶圖像
研究:https://www.youtube.com/watch?v=zAWO9rldyUE, https://www.youtube.com/watch?v=TEMUOaamcDA,https://www.raywenderlich.com/129059/self-sizing-table-view-cells
目前代碼
func configureCell(post: Post){
self.post = post
likesRef = FriendSystem.system.CURRENT_USER_REF.child("likes").child(post.postID)
userRef = FriendSystem.system.USER_REF.child(post.userID).child("profile")
self.captionText.text = post.caption
self.likesLbl.text = "\(post.likes)"
self.endDate = Date(timeIntervalSince1970: TimeInterval(post.time))
userRef.observeSingleEvent(of: .value, with: { (snapshot) in
let snap = snapshot.value as? Dictionary<String, Any>
self.currentUser = MainUser(uid: post.userID, userData: snap!)
self.userNameLbl.text = self.currentUser.username
if let profileImg = self.currentUser.profileImage {
self.profileImg.loadImageUsingCache(urlString: profileImg)
} else {
self.profileImg.image = #imageLiteral(resourceName: "requests_icon")
}
})
// This is where I belive I need to determine wether or not the cell should have an image or not.
if let postImg = post.imageUrl {
self.postImg.loadImageUsingCache(urlString: postImg)
}