I'm trying to follow along with a video course to implement photo gallery with Unsplash.
First I implemented UIViewController with searchbar and navigation bar in it
PhotoCollectionViewController: UIViewController
and manually adding searchbar and navigation bar
//MARK: - Nav bar inelkaar steken hier
private func setupNavigationBar(){
let titleLabel = UILabel()
titleLabel.text = "Photos"
titleLabel.font = UIFont.systemFont(ofSize: 15)
titleLabel.textColor = .black
navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: titleLabel)
navigationItem.rightBarButtonItems = [addBarButtonItem, actionBarButtonItem]
}
and the same for searchbar
after this the PhotoCollectionViewController: UIViewController
inheritance seemed be wrong what I did, and I need to change it to UICollectionViewController
I make then another controller inherited from UICollectionViewController with the same logic PhotoCollectionViewController: UICollectionViewController
It compiles without any issues, but I don't see navigation an search bar anymore
How can I fix this?
CodePudding user response:
May be your collectionView is hiding search bar and navigation bar. check collectionView constraints. (specially top anchor)
// PS: I could comment, but I don't have 50 reputation.
CodePudding user response:
maybe you can try this:
Check the top constraint first of your collectionView. And maybe you can add this code to you viewDidLoad() :
self.navigationController?.setNavigationBarHidden(true, animated: false)
if you use ScollView at fullscreen (SuperView), you can use this :
scrollView.contentInsetAdjustmentBehavior = .never
for searchBar IBOutlet you can add this :
searchBar.becomeFirstResponder()