Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can get the navigation controller's <code>viewControllers</code> property and use it, perhaps like this:</p> <pre><code>UILabel *label = ((SomeViewController *)[self.navigationController.viewControllers objectAtIndex:1]).myLabel; </code></pre> <p>However, that is not reliable. Since the “previous” view is off the screen, the system can unload it to free up memory. Then <code>label</code> will be <code>nil</code>.</p> <p>You could force that other view controller to reload its view (if it has been unloaded) by accessing the view controller's <code>view</code> property.</p> <p>But really this smells like bad design. You should almost never try to access the views of a view controller when that view controller's view is not on screen. Remember how the system can unload a view controller's view if the view is off-screen? If some <code>UILabel</code> under that view contained the only copy of important data, that data is now gone!</p> <p>Any important data needs to be stored somewhere <em>other</em> than a view - perhaps in a property of the view controller, or in a model object. You should ask the view controller for the data, or for the model object that contains the data. A view controller's view objects should almost always be considered a private implementation detail of the view controller, not exposed to other classes.</p> <h2>EDIT</h2> <p>Your question is puzzling because you talk about popping <code>ViewB</code> and returning to <code>ViewA</code>, but your code only creates and pushes a <code>ViewA</code>. <code>ViewB</code> is not mentioned in the code.</p> <p>I will assume that your ViewA creates and pushes a ViewB. So you should give <code>ViewB</code> a property of type <code>ViewA</code>, like this:</p> <pre><code>@class ViewA; // forward declaration to avoid circular imports @interface ViewB @property (weak, nonatomic) ViewA *aView; </code></pre> <p>Then, when your <code>ViewA</code> creates a <code>ViewB</code> instance, you set the <code>aView</code> property:</p> <pre><code>@implementation ViewA - (void)pushViewB { ViewB *bView = [[ViewB alloc] init]; bView.aView = self; [self.navigationController pushViewController:bView animated:YES]; } </code></pre> <p>Now your <code>ViewB</code> has access to the <code>ViewA</code> that created it, and can set the properties of that <code>ViewA</code>.</p>
 

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