UINavigationBar not loading correctly

Viewed 217

I know there are a lot of questions out there on this topic; however, none of those answers have helped me and I have tried so many ways of going about solving this. My problem is that my bar button will not show up, originaly, but when the viewcontroller is presented later on in the app it will show up then but the navigation title won't show up. I'm not sure why that is, but I believe it has something to do with the SwipeNavigationController framework that I'm using. My goal is to have the button show up as it's supposed to when the user swipes left to get to that view, and also when the view is later called and presented to look the same. The code for adding the navItem is below:

let cameraBarButton = UIBarButtonItem(image: #imageLiteral(resourceName: "cameraIcon"), style: .plain, target: self, action: #selector(goToCamera))
navigationItem.rightBarButtonItem = cameraBarButton

Please look at this other post to get a little better understanding of the framework. As well as here is the code on how I set up the navigation bar:

 override func viewDidLoad() {
    super.viewDidLoad()

    setupView()

    let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
    let displayWidth: CGFloat = self.view.frame.width
    let displayHeight: CGFloat = self.view.frame.height

    messagesTableView = UITableView(frame: CGRect(x: 0, y: barHeight, width: displayWidth, height: displayHeight - barHeight))
    messagesTableView.register(BlankCell.self, forCellReuseIdentifier: blankCellID)
    messagesTableView.dataSource = self
    messagesTableView.delegate = self
    self.view.addSubview(messagesTableView)

    view.backgroundColor = UIColor.white

    setupNavButtons()
    setupNavBar()

   showNoMessagesLabel()



    navigationController?.isNavigationBarHidden = false

    if #available(iOS 11.0, *) {
        navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    } else {
        // Fallback on earlier versions
    }
}
override func viewWillAppear(_ animated: Bool) {



    if #available(iOS 11.0, *) {
        navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
        setupNavBar()
    } else {
        setupNavBar()
    }
}

func setupNavBar() {



    UIApplication.shared.statusBarStyle = .lightContent
    self.navigationController?.isNavigationBarHidden = false
    self.navigationController?.navigationBar.topItem?.title = "Messages"
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    self.navigationController?.navigationBar.barTintColor = UIColor.pinkNeonColor
    self.navigationController?.navigationBar.tintColor = UIColor.white


}

func setupNavButtons() {
    let cameraButton = UIButton(type: .system)
    cameraButton.setImage(#imageLiteral(resourceName: "cameraIcon").withRenderingMode(.alwaysOriginal), for: .normal)
    cameraButton.frame = CGRect(x: 0, y: 0, width: 34, height: 34)
    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: cameraButton)
}
0 Answers
Related