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

  • Home
  • SEARCH
  • 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 6038077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:09:58+00:00 2026-05-23T06:09:58+00:00

I have a UINavigationController (to use like a wizard page) which I create programmatically

  • 0

I have a UINavigationController (to use like a wizard page) which I create programmatically and I need to display a “Cancel” button to cancel the process in any UIViewController.

Creating the UINavigationController:

FirstVC *firstVC = [[[FirstVC alloc] initWithNibName:@"FirstPage" bundle:nil] autorelease];
firstVC.delegate = self;

navigationController = [[UINavigationController alloc] initWithRootViewController:firstVC];
[self.view addSubview:navigationController.view];

Adding Cancel Button:

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelRequestNewLeave:)];
navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton;
[cancelButton release];

But when I push a second page to UINavigationController the cancel button is not shown on the UINavigationBar. If I go back to first page, the cancel button is there. So, apparently the button is added only for the first view. I believe this is because I’m not subclassing UINavigationController, because I need to use it in a subview. But I don’t know how to set the rightBarButtonItem in a UINavigationController which is created programmatically.

navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton;

Can someone shed a light on this?

Thanks in advance.

  • 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-23T06:09:59+00:00Added an answer on May 23, 2026 at 6:09 am

    The navigation item is per view controller. The navigation bar draws its contents from the navigation item of the view controller whose view it’s currently framing, which corresponds to the view controller at the top of the navigation controller’s stack.

    You basically need each view controller to stick a cancel button in its navigation item. You can do any of the following:

    • Copy-paste the code into all relevant view controllers.
    • Move the code into a utility function or class and call that.
    • Create a common superclass for all relevant view controllers that handles setting up the cancel button for its subclasses.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have always wondered why all apple code samples use code like this: UINavigationController
I have a snippet to create a 'Like' button for our news site: <iframe
I have an iPhone application using UINavigationController and would like to customize the elements
I have a UITabBar + UINavigationController application which often needs data from the internet.
I have a application that make use of a UINavigationController. In the rootview I
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
In my UIViewController I have a UINavigationController with a default back button. When the
My app is building purely programmatically on UITabBarController above a UINavigationController, which are both
I have a UINavigationController containing an UIViewController initialized with a UIView. The UINavigationController also

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.