Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should set your AViewController as the delegate of your BViewController so you can message it back after a particular event. Using a delegate will also allow better decoupling of your ViewControllers.</p> <p>In your BViewController, define a protocol like this :</p> <p>BViewController.h : </p> <pre><code>@protocol BViewControllerDelegate &lt;NSObject&gt; - (void)viewB:(UIViewController *)didEnterMessage:(NSString *)message; @end </code></pre> <p>and add a delegate property :</p> <pre><code>@property (nonatomic, weak) id &lt;BViewControllerDelegate&gt; delegate; </code></pre> <p>When the user enter the message in your BViewController and hit the button that pops the BViewController to show to AViewController do this :</p> <pre><code>- (IBAction)messageEntered { if ([self.delegate respondsToSelector:@selector(viewB:didEnterMessage:)]) { [self.delegate viewB:self didEnterMessage:self.yourTextField.text]; } } </code></pre> <p>Your AViewController should implement the BViewControllerDelegate protocol like this :</p> <p>AViewController.h :</p> <pre><code>@interface AViewController &lt;BViewControllerDelegate&gt; </code></pre> <p>When your AViewController creates the BViewController, it should set itself as its delegate before presenting it. Might look like this :</p> <pre><code>BViewController *bvc = [[BViewController alloc] init…]; bvc.delegate = self; </code></pre> <p>And finally, your AViewController should implement the viewB:didEnterMessage: method :</p> <pre><code>- (void)viewB:(UIViewController *)didEnterMessage:(NSString *)message { self.myLabel.text = message; } </code></pre> <p>That's the cleanest way to do that, IMHO.</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