Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a protocol and set VC1 as delegate of VC2, and using <code>prepareForSegue</code> to set VC1 as VC2's delegate should work. I know that you said it didn't work, but I can't see why. Have a try with this :</p> <p>Give an identifier to your segue (on storyboard), and implement <code>prepareForSegue</code> as shown below :</p> <p>VC2Delegate.h :</p> <pre><code>@protocol VC2Delegate - (void)updateLabel:(NSString *)text; @end </code></pre> <p>VC1.h :</p> <pre><code>#import "VC2Delegate.h" @interface VC1 : UIViewController &lt;VC2Delegate&gt; // All your stuff @end </code></pre> <p>VC1.m :</p> <pre><code>- (void)updateLabel:(NSString *)text { [_label setText:text]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"YourSegueIdentifier"]) { VC2 * vc = [segue destinationViewController]; [vc2 setDelegate:self]; } } </code></pre> <p>VC2.h :</p> <pre><code>#import "VC2Delegate.h" @interface VC2 : UIViewController @property (weak, nonatomic) id&lt;VC2Delegate&gt;delegate; @end </code></pre> <p>VC2.m</p> <pre><code>- (void)textWasUpdated { // or whatever method where you detect the text has been changed if (_delegate) [_delegate updateLabel:[_textView text]]; } </code></pre> <p>Tell me if it works. Else, is prepareForSegue even been called ?</p> <p>EDIT : Updated my answer (wasn't exactly what you needed). But as you say it doesn't work :</p> <ul> <li>Is prepareForSegue called ?</li> <li>If so, is the delegate method called ?</li> <li>If the delegate method isn't called, check that delegate is not <code>nil</code>.</li> </ul> <p>You might want to remove the segue, and present it modally by yourself, using <code>presentViewController:animated:completion:</code>, like that :</p> <pre><code>- (IBAction)buttonWasTapped { static NSString * const idModalView = @"modalView"; static NSString * const storyBoardName = @"MainStoryBoard" UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil]; VC2 * vc = [storyboard instantiateViewControllerWithIdentifier:idModalView]; [vc setDelegate:self]; [self.navigationController presentViewController:vc2 animated:YES completion:nil]; } </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. 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