Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Most of the posts so far have focused on creating the button, and are very correct. The following answers the rest of the question:</p> <blockquote> <p>When I click the button and the second view is displayed, how do I programmatically change the text of the button (to say 'back', for instance)?</p> </blockquote> <p>The easiest way, if I understand your circumstance correctly, is to use the plug-n-play UINavigationBarController. First you want to push your second view controller onto the view stack:</p> <pre><code>// In firstViewController.m self.navigationController = [[UIViewController alloc]initWithNibName:@"secondView" bundle:nil]; [self pushViewController:secondViewController animated:TRUE]; </code></pre> <p>When your second view controller is shown, you should automatically get a back button on the left side of the nav-bar. If there is a need to change the text of that back button, you can simply refer to it like so:</p> <pre><code>// In secondViewController.m -(void)ViewWillAppear { [self.navigationItem.backBarButtonItem setText:@"GoBack"]; } </code></pre> <p>There are also the left and rightBarButtonItem(s) which are handy for more complex navigation. Here is a less plug-n-play scenario:</p> <pre><code>// In secondViewController.h -(IBAction)goBack; (this should appear as an action in your associated nib file) // In secondViewController.m -(void)viewDidLoad { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"GoBack" style:UIBarButtonItemStylePlain target:self action:@selector(goBack)]; } -(IBAction)goBack { // logic to be done before going back [self popViewControllerAnimated:secondViewController animated:TRUE]; } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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