Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was probably added to the documentation quite recently as I stumbled across this today for the first time. Moreover, in nearly every sample code that I've seen the initialization of the bar buttons happens in the viewDidLoad method - which is obviously not the best place to do this according to the quoted statement.</p> <p>What Apple says us with this is that there can be situations where the content of the navigationItem is requested when the viewDidLoad method is not executed yet or not gets executed at all. This happens when you push more than one viewcontroller at once. E.g. by using the <em>setViewControllers:animated:</em> interface or by doing something like this:</p> <pre><code>ViewController1 *firstViewController = [[ViewController1 alloc] init]; ViewController2 *secondViewController = [[ViewController2 alloc] init]; [navigationController pushViewController:firstViewController animated:YES]; [navigationController pushViewController:secondViewController animated:YES]; </code></pre> <p>In this case the viewDidLoad method of <em>firstViewController</em> will not be called until the user navigates back to it. If you have set the <em>title</em> property in <em>firstViewController</em>, you would expect to have the back button labelled with the title you set in <em>firstViewController</em>. However the back button will be called "Back", as the title property of <em>firstViewController</em> is nil when UINavigationController asks for it.</p> <p>The conclusion is: Tying the creation of bar button items to the creation of the view works for most situations. Nevertheless keep in mind that you can have situations where you need the navigationitem information before or without creating the view. In this case consider initializing the <em>navigationItem</em> property in the viewcontrollers <em>init</em> method.</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.
    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