0

I'm having trouble finding a way to remove a 'ghost' back button (nothing but a blue back arrow) when I initialize my uinavigationcontroller with a custom uinavigationbar. When I click that back button, I then see my custom navigationbar, but I would like to not have to click that back button.

I've tried almost all other solutions, including setHidesBackButton, etc. and playing with the order in which I call these functions.

class TabsVC : UITabBarController {

func setupTabBar() {
    // setup feed tab
    let navVC = UINavigationController(navigationBarClass: NavBar.self, toolbarClass: nil)

    self.navigationItem.setHidesBackButton(true, animated: false)

    let feedVC = FeedVC()
    navVC.pushViewController(feedVC, animated: false)
    let feedIcon = UIImage.fontAwesomeIcon(name: .home, textColor: ColorConstants.baseColor, size: CGSize(width: 40, height: 40))
    navVC.tabBarItem = UITabBarItem(title: "", image: feedIcon, tag: 1)

    // other tabs stuff
}

class NavBar : UINavigationBar {

func prepare() {
    let item = UINavigationItem(title: "")
    let titleV = titleView()
    item.titleView = titleV

    item.hidesBackButton = true
    item.setHidesBackButton(false, animated: false)

    item.leftBarButtonItem = UIBarButtonItem(image: UIImage.fontAwesomeIcon(name: .userCircle, textColor: ColorConstants.baseColor, size: CGSize(width: 40, height: 40)), style: .plain, target: nil, action: nil)
    item.leftBarButtonItem?.tintColor = .white
    item.leftBarButtonItem?.action = #selector(moveToProfileScreen)
    self.pushItem(item, animated: false)
}

I just want to be able to see my custom nav bar from the beginning, and not have to click an empty back button to see the nav bar. Thanks!

2
  • Let me ask the obvious question: why hide the back button at all? Why not just use your custom image? Or is moveToProfileScreen() something more complex than popping off the current view controller? Commented Jan 10, 2019 at 20:18
  • When I try to do it that way, the profile button just gets added to the right of the previously empty back button, and acts as part of the back button, so that I still click it to see the full nav bar. Commented Jan 10, 2019 at 20:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.