Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding same button to all view controllers in UINavigationController
    primarykey
    data
    text
    <p>I have a <code>UINavigationController</code> (to use like a wizard page) which I create programmatically and I need to display a "Cancel" button to cancel the process in any <code>UIViewController</code>.</p> <p><b>Creating the <code>UINavigationController</code>:</b></p> <pre><code>FirstVC *firstVC = [[[FirstVC alloc] initWithNibName:@"FirstPage" bundle:nil] autorelease]; firstVC.delegate = self; navigationController = [[UINavigationController alloc] initWithRootViewController:firstVC]; [self.view addSubview:navigationController.view]; </code></pre> <p><b>Adding Cancel Button:</b></p> <pre><code>UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelRequestNewLeave:)]; navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton; [cancelButton release]; </code></pre> <p>But when I push a second page to <code>UINavigationController</code> the cancel button is not shown on the <code>UINavigationBar</code>. 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 <code>UINavigationController</code>, because I need to use it in a subview. But I don't know how to set the <code>rightBarButtonItem</code> in a <code>UINavigationController</code> which is created programmatically.</p> <pre><code>navigationController.topViewController.navigationItem.rightBarButtonItem = cancelButton; </code></pre> <p>Can someone shed a light on this?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload