Present Photo Selector
Instagram Firebase
We are now ready to allow the user to start adding in photos to the application by using the plus button in the middle of the Tab Bar. We'll look at how to custom the behavior of UITabBarController to handle pressing of a button and disabling the default behavior. Furthermore, our logic will present an image picker controller that the user can use for photo selection.

Comments (26)
Anthony
6 years ago
Hello Brian, This is maybe a weird question but I will go to a place for a long time with almost no wifi, so can I download the course? I hope you understand my situation
Brian Voong
6 years ago
Anthony
6 years ago
I understand, Thank you for helping me
AlexKey
6 years ago
Hi Brian, whats that error that you see every now and then when building the app? "the request was denied by service delegate for reason busy" I see it every 10 builds or so, what does it mean? people say to check scheme settings or to quit simulator, but I don't find these to be applicable in my case. Thanks for the video!
Brian Voong
6 years ago
AlexKey
6 years ago
It pops up every now and then in your video when you attempt to build the app, you click it away and continue but I guess you didn't notice
Kenny Ho
6 years ago
Hey Brian, I have a question concerning photos. Which I select photos, I don't see my personal photos that I have but instead I only see the generic 5 photos that Apple has. How are you able to access all your photos to post? Your help would be much appreciated! Thanks
Brian Voong
6 years ago
Kenny Ho
6 years ago
Thank you very much!!! :)
Krubel Habteyes
6 years ago
Does anyone know what this error means: 'UICollectionView must be initialized with a non-nil layout parameter'
Brian Voong
6 years ago
Krubel Habteyes
6 years ago
Where do i initialize it?
passion
6 years ago
I don't know why Firebase look slow, app already loaded and it wait data from firebase around 3-5 seconds
Casey West
6 years ago
I have the same issue. Please respond
Brian Voong
6 years ago
NuclearDuck
6 years ago
Hey Brian, One of Instagram's recent updates is the ability to select multiple photos to post. Can you give me some tips on how to program this feature?
Casey West
6 years ago
It takes multiple seconds for name and photo to load...it also flashes the user id from firebase. Please let me know of any optimizing I can do to avoid this. :)
Casey West
6 years ago
Could you maybe make a quick video showing how to make an activity indicator for that time?
Brian Voong
6 years ago
Casey West
6 years ago
Thanks a ton!
oalansari82
6 years ago
So far so good. I just faced an issue here. I am building the app in my iPhone as I work through to test it. After this lesson I am getting this error. I am not sure what causes it and google is not very helpful clang: error: linker command failed with exit code 1 (use -v to see invocation) Any ideas?
oalansari82
6 years ago
OK so I just did Product > Clean that fixed the issue. In case anyone faces the same issue.
smiller193
6 years ago
Is anyone having an issue with the input accessory view getting stuck at the bottom? When exiting comment screen
stonypig1
6 years ago
how can we select multiple photos at the same time and then display it? any article talks about it? thanks
Nick Stanislawski
5 years ago
I’m wondering how you would be able to post videos
Brian Voong
5 years ago
Nick Stanislawski
4 years ago
I am currently working on a project that I was able to do from what I have learned from your courses. There are some more advanced features that I am trying to implement. I was wondering if you do individual sessions or even freelance?
corbinyo
5 years ago
I am trying to add a footer but having issue with this error: 'collectionView(_:viewForSupplementaryElementOfKind:at:)' has already been overridden' I'm sure it has to do with my method of trying to make a foot by replicating how we made the header...
corbinyo
5 years ago
If anyone is wanting a solution to this problem - Of course Brian has us covered: check out this video: https://www.youtube.com/watch?v=2fcf9yFe944&t=618s
Maximilian Osborne
5 years ago
Is there a way to globally have the .lightContent in the status bar style on every view controller but locally decide to hide status bars? I am having trouble combining .lightContent for the status bar style and hiding the status bar when on the PhotoSelectorController. I seem to be able to only do one or the other. Following your instructions I can get the status bar to hide. however also implementing the override var preferredStatusBarStyle: UIStatusBarStyle{ get{ return .lightContent } } or override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent } does not seem to do anything. So I came across https://stackoverflow.com/questions/26956728/changing-the-status-bar-color-for-specific-viewcontrollers-using-swift-in-ios8 and followed the instructions of the highest voted answer. I then managed to implement the .lightContent. However with "View controller-based status bar appearance" = NO in info.plist the status bar could not be hidden.
Maximilian Osborne
5 years ago
I also played around with setNeedsStatusBarAppearanceUpdate() but this still didn't get me further Thank you for your help!
Brian Voong
5 years ago
Maximilian Osborne
5 years ago
Thank you for your quick response! I'm unsure how to continue, as I wouldn't know how to call this class appropriately. I've now created this class: class LightNavigationController: UINavigationController { override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent } } could you give an example how to call this in say the UserProfileController?
Ashim Dahal
5 years ago
In swift 4 use this code to find index of view controller let index = tabBarController.viewControllers?.index(of: viewController)
Ashim Dahal
5 years ago
Apparently, The cell didn't appear on view... any reason why this could have happened... I could see the red background from view did load. Here is my code. Couldn't figure out why? class PhotoSelectorController: UICollectionViewController{ let cellID = "cellID" override func viewDidLoad() { super.viewDidLoad() collectionView?.backgroundColor = .red collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cellID") } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 5 } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath) cell.backgroundColor = .blue return cell } }
nitpa7
5 years ago
did you find any solution for this?
Shahrukh Mohammad
5 years ago
That’s probably because you are using a more recent version of swift and Xcode which requires a “size” assignment for each collection view cell. This wasn’t a requirement in swift 3 which Bryan is using in the video. Hope that helps :-)
AlfieLBTA
5 years ago
Hey Brian , how do you come up/learn with things like: what you did on minute 2.20 where you need to set up the delegate as self, pretty shady things there to learn in my opinion , i could hit my head for days with out coming with that up.
duypham
5 years ago
Hi Brian, I have the same problem with Ashim Dahal that the cell didn't appear on view. I tried to fix this in couple days already but can't find the solution. Please review the code and help us fix this so i can get back on studying this course. Thank you
duypham
5 years ago
Thank for helping me fix it, Brian. You're the best.
astericky
4 years ago
What was the fix?
joker45
5 years ago
Hey guys, I can give here the same suggestion, like previous. To create PhotoSelectorController.swift, just use -> "File -> New -> File -> (iOS) -> Cocoa Touch Class (or just press cmd + n) Than define "Class:" -> PhotoSelectorController "Subclass of:" -> UiCollectionViewController "Language:" -> Swift After this you have a full defined UICollectionViewController with after "import UIKit" defined reuseIdentifier. ->> private let reuseIdentifier = "Cell" for Header just add for example: ->> private let reuseIdentifierHeader = "Header" take care of already defined "override func numberOfSections(in collectionView: UICollectionView) -> Int {" set to "return 1" (from return 0) or completly comment out.
rgarcia
4 years ago
I had the same problem make check: let layout = UICollectionViewFlowLayout() make sure is FlowLayout my problem was I used: let layout = UICollectionViewLayout()
owenh07
4 years ago
Oh wow. I can't believe that slipped by me... Thanks!
chandanbrown2@gmail.com
4 years ago
Hi Brian, I'm having an issue with my navigationcontroller.pushViewcontroller. I've tried pushViewController and present, but its not doing any presenting or pushing. Instead of using the photoselector, I'm doing the video selector from uiimagepickercontroller.. I can choose a video, but when I click choose to go to my shareVideoVC -> It doesn't present. I put a print statement with my handleNext function which contains the navigationcontroller.pushviewcontroller and that statement prints and shows the func is working and going through. I also put a breakpoint and it shows that the viewdidLoad renders, but it just doesn't display the view. Please help!
Brian Voong
4 years ago
chandanbrown2@gmail.com
4 years ago
Oh hey Brian that was quick. I'm only using my phone because for some reason Xcode forces me to store extra gb on my computer storage when I run different simulators. It's more a presenting nav challenge than a video issue. All my video stuff seems to work fine. I'm saving all the data I need... but the present/push is strange because it doesn't display my new VC.
chandanbrown2@gmail.com
4 years ago
I'm shifting from the storyboard to the programmatic development life, if you know what I mean :D
Brian Voong
4 years ago
chandanbrown2@gmail.com
4 years ago
Okay, problem solved. Did that and learned some interesting things. One thing is that it won't present correctly if the very root of the view controller you initially made isn't a UINavigationController(rootVC: _______). I initially presented with a normal controller at my first root controller. Now that I made it a uinavcontroller it works well.
Daniel Peach
4 years ago
And bam just like that delegates clicked finally
astericky
4 years ago
Hmmm At 13:12 where Im supposed to see 5 blue cells in the UICollectionCiew when I run the app I am not seeing the cells. Does anyone have any ideas as to what could be wrong here?
astericky
4 years ago
nevermind I figured it out. I was using UICollectionViewLayout and not UICollectionViewFlowLayout.
MaxApp
4 years ago
Hey Brian, a quick question! Remember the sign up screen where you imported a method that can select a photo for the plusPhotoButton. Would you recommend or use this method for presenting the add photo instead of coding the photo selection? Thanks
wdyben
3 years ago
prefersStatusBarHidden don't work in PhotoSelectorController if we don't specify navController.modalPresentationCapturesStatusBarAppearance = true in the MainTabBarController
Kyle Griffin
3 years ago
Whenenever I use present(viewController), it leaves a gap at the top of my screen. almost like there's a setting to not cover up the status bar. push(viewController) works as intended and the viewcontroller fills the entire screen. Any idea how to fix the present method?
Brian Voong
3 years ago
Kyle Griffin
3 years ago
Easy enough lol. I was making it more complicated than it needed to be. I thought i needed the UIAdaptivePresentationControlelrDelegate or something. Anyway, thanks to you, I'm pretty sure I'm going to land an iOS developer role after passing the coding test with flying colors. I've only been watching your videos for about a week now (Granted - about 12 hours a day lol) but other than that, I've have had minimal experience with iOS prior to. But a lot of concepts I was able to carry over for web development, just need to hone my skills a bit in the object oriented concepts. I'm getting a little better each day though. I have a question though: the engineering lead told me they use storyboards. Will it be easy to adapt to storyboards versus doing everything programmatically if I have to?
Muhammad Ahmad Zafar
3 years ago
1: I used this code to hide the status bar when I am in "UIViewController " then this method works override var prefersStatusBarHidden: Bool { return true } 2: but when you are using UICollectionViewController these methods are not supported well so I will use the old method so use this extension because it does not show you 'isStatusBarHidden' was message deprecated in iOS 13.0 'isStatusBarHidden' was deprecated in iOS 13.0 extension UICollectionViewController { func hideStatusBar(){ UIApplication.shared.isStatusBarHidden = true } func showStatusbar(){ UIApplication.shared.isStatusBarHidden = false } }
Brian Voong
3 years ago
Muhammad Ahmad Zafar
3 years ago
thank you Brain it worked this course has helped me a lot
srithan
3 years ago
I didn't understand how to implement what brian said. Can you help me out?
ZacharySmouse
3 years ago
So we need to initialize the PhotoSelectorController as an UINavigationController and just make an UICollectionView variable?
Muhammad Ahmad Zafar
3 years ago
Brian please tell me if is any way to hide the status bar in UICollectionViewController class
HELP & SUPPORT