Fetch Comments
Instagram Firebase
With the list of comments now inserted into Firebase Database, we're ready to render them out into our UICollectionView. We'll first start by laying out our CommentCell views in our controller. Next, we perform the fetching of comment based on the post that we are tapping into. Performing all of this logic will get us ready for the next lesson on further details of each cell.

Comments (17)
Fred van Rijswijk
6 years ago
Hi Brian, 2 videos, great!! ;-) Little question, can you add a way to handle if there are no comments to that post and show the user empty screen with a text label or image... maybe is this a good place to show that kind of functionality. Thnx
Brian Voong
6 years ago
Jesus Miguel Rosado Perdomo
6 years ago
Hi Brian excellent tutorials, how can we fetch likes and followers???
Arvid Schneider
5 years ago
For one sided content insets, a bit more convenient would be: collectionView?.contentInset.bottom = -50
smiller193
5 years ago
Hey brian I have a quick question. I have already implemented the comments feature pretty nicely. However, now I want users to be able to reply to comments similar to how instagram has currently. How would I go about implementing that
Drew Pasma
5 years ago
Brian great videos thus far. Couple problems I am having and wondering if you solve them later. ->When I refresh the home controller when there is no new posts, the app crashes ->When I insert a comment the TextField does not clear If these get fixed in the future, please let me know. Thank you, Drew
Drew Pasma
5 years ago
Actually when I pull the refresh controller down really far it crashed but when I pull it down a normal height it works. Any thoughts to why this could be happening?
Drew Pasma
5 years ago
Just kidding. Fixed the refresh crash, but still wondering about the comment clear
stonypig1
5 years ago
one thing I am confused: var comments = [Comments]( ), this comment array is set to empty before we draw data from firebase, but why outside the function? shouldn't be inside the function fetchComments( ) function ? thanks
Abhishesh
5 years ago
U want to fill out the array then use it on other functions such as getting the total number of rows and getting the comment in that particular index. If you declare it inside the function, other functions can't access it
Chris Karani
5 years ago
We want `var comments = [Comments]( )` on the outer scope to reference it in other parts of our code
nschucky
5 years ago
has anyone find out how to fix the inputAccessoryView on iPhoneX in a way that the collectionView don't show up on the bottom of it in that space between the inputAccessoryView and the bottom of the view? getting this issue after i anchored the inputAccessoryView to the safeArea
Yevhenii
5 years ago
The fix is to create an class CustomAccessoryView: UIView and set couple of properties. First is override intrinsicContentSize: CGSize { return .zero } and the second is set autoresizingMask = .flexibleHeight You no longer need to set CustomAccessoryView frame and just in your controller: override var inputAccessoryView: UIView? { return self.customAccessoryView } In order to manipulate the height of this custom view use constraints of its subviews.
appUser
4 years ago
I'm having this issue too, were you able to solve it?
rehan1531
5 years ago
ref.observe(.childAdded) ,,, why .childAdded , we used .value all time so this time why its .childAdded . Thanks in advance
ajeannoel
5 years ago
Hello Brian, thank you so much for those great videos and for allowing us to get our hands dirty on the code (the only way to really understand what's going on under the hound). I'm experiencing a strange bug, my collection view is not scrolling when the CommentsController just appeared until I click on the textInput, I've tried a couple of fixes: collectionView.bounce = true, collectionView.alwaysBounceVertical = true for the collectionView to be able to scroll immediately but now, I can't see the scrollbar anymore. Do you or guys here have any idea how to fix this behavior? (I've copied/pasted the sample source code but same thing). I'm using a real iPhone 6S + iOS 11.4.1. Thanks
Jaylon22
4 years ago
Hey Brian, I'm really love the instagram course, this is the best course i ever spent money on. Just a quick question when i fetch the comments and the data reload the cells seem to be out of order do you have a thought about how this could be fix?
Brian Voong
4 years ago
Jaylon22
4 years ago
Thank you for the fast response! The problem is that the comment varaible is not ordering the snapshot's value correctly so i'll have to see why that is.
Jaylon22
4 years ago
Hey Brian, So the comments are out of order and i tried to put them in order using various ways of sorting. I notice that when i use a dictionary for the user id they are out of order but when i change the user id to equal the current user id. The comments are in order but it only display the log in user. Could you please help me? Thank you and have a bless day.
edison1
4 years ago
Has anyone figured out how to go to an users profile from comment when you tap the image? This is what I've tried so far. Any help would be huge @objc func handleProfile() { print("123 from cell") // guard let usecomr = user else {return} // delegate?.didSeeProfile(user: user) guard let comment = comment else {return} delegate?.didtdidTapProfile(comment: comment) } func didtdidTapProfile(comment: Comment) { print("controller") let user = UserProfileController(collectionViewLayout: UICollectionViewFlowLayout()) user.userId = comment.user.uid navigationController?.pushViewController(user, animated: true) }
Brian Voong
4 years ago
edison1
4 years ago
It's only printing the "123 from cell" I've been stuck here for a while, not sure what else what I can do?
mao
4 years ago
Brian, when I click "Submit" without any text input, it still shows an empty text is sent. Could you please tell me what is the best method to disable the submit button when there is no input?
TWei
4 years ago
Does our Login screen's login button has the similar feature?
Brian Voong
4 years ago
mao
4 years ago
Thanks for the recommendation.
malrhex
4 years ago
Pretty good stuff! Amazing! You are a really great teacher!
malrhex
4 years ago
Hello Brian, hope you are doing fine!. I was wondering how can I use the Notification Center over here, basically I need something and make it lazy var, but I cannot make a CommentCell lazy var
malrhex
4 years ago
This is the context of what I'm talking about: let bottomSpace = view.frame.height - CommentCell.frame.origin.y - CommentCell.frame.height while: // let's try to figure out how tall the gap is from the latest comment cell to the bottom of the screen
Brian Voong
4 years ago
malrhex
4 years ago
actually its from here: https://www.letsbuildthatapp.com/course_video?id=4162 you tell me to get that course to learn notification center while keyboard is showing up. Simple, I'm trying to scroll all the way down to the latest comment. UIView.animate(withDuration: 0, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: { self.view.layoutIfNeeded() }, completion: { (completed) in if self.isFirstResponder { let indexPath = NSIndexPath(item: self.comments.count - 1, section: 0) self.collectionView.scrollToItem(at: indexPath as IndexPath, at: .bottom, animated: true) } }) No luck. On your video you just say stackView make it lazy and then you work from there. on this chat. https://www.letsbuildthatapp.com/course_video?id=152 24:43 you don't have stackView but you just pull the padding constraint of the container. two different examples and I can't get it done.
Cinquain
4 years ago
Video was lit
Ahmed.Q
3 years ago
Hi, I am trying to fetch data from firebase and then load data in UICollectionView, but when populating data it shows only one element repeated for all cells with the right count, would be possible to have a look at my problem I have posted it on Stackoverflow https://stackoverflow.com/q/59468529/7552578?stw=2 Thanks.
HELP & SUPPORT