Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:48:44+00:00 2026-05-26T12:48:44+00:00

In an iOS app, how can I determine whether a back button is displayed?

  • 0

In an iOS app, how can I determine whether a back button is displayed? Ideally, I’d like to know this in my controller’s loadView method.

Here’s what I’ve tried in loadView, viewDidLoad, and viewWillAppear:

if (self.navigationItem.backBarButtonItem)

and this:

if (self.navigationItem.leftBarButtonItem)

Neither of those work – they’re always nil (the expression evaluates to false), even when there is a back button on the screen. What I’d ultimately like to do is set a Cancel button as the self.navigationItem.leftBarButtonItem, but only if there’s no back button. If there is a back button, we don’t need the Cancel button. As it is, setting the leftBarButtonItem is overriding the back button, so we’re seeing a Cancel button all the time – even when there should be a back button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:48:44+00:00Added an answer on May 26, 2026 at 12:48 pm

    You’re asking the wrong object for its backBarButtonItem. This property controls how an object is represented when it is the “back” item in the navigation stack.

    Therefore, you need to be asking the view controller at the level below where you are in the navigation stack what its backBarButtonItem is:

    int n = [self.navigationController.viewControllers count] - 2;
    if (n >= 0)
        if ([(UIViewController*)[self.navigationController.viewControllers objectAtIndex:n]navigationItem].backBarButtonItem == nil)
            // Do your thing....
    

    You may need to check if the navigation controller has added your viewController to the stack at the time you are executing this code, the top view controller may still be the previous one. I’ve checked in viewWillAppear and the stack does contain the new top controller at this point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I determine if the device that is running my app is ios
I am developing an iOS app. How can I know the current section that
Anybody can tell me how to make Twitter's row menu in iOS app like
Does anybody know where an iOS app can see the default headers that NSUrlRequest
In my iOS app I would like that user can download some jpg file
UPDATE It looks like this problem has been quietly fixed in iOS 4.3. Up
I’m embedding YouTube videos in a UIWebView for an iOS app. I’m using Method
I'd like to build a preferences screen in my iOS app that has a
I understand that, besides some general settings, an iOS app can only see the
I know what code is needed to cause my iOS app to open a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.