Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are honestly very close. Container views will call the prepareForSegue: method, so you should be initializing the second view controller's delegate in this method:</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"TypeContainerViewSegueNameHere"]) { SecondViewController *viewController = (SecondViewController *)segue.destinationViewController; viewController.delegate = self; } } </code></pre> <p>This way you know that you are getting the instance of SecondViewController that will be in use. Also, you do not need to redeclare the delegate method in your SecondViewController.h file:</p> <pre><code>-(void)colourDidChange:(UIColor *)theColour; </code></pre> <p>Finally, in storyboard set the title of the container view segue to SecondViewController to whatever title you like and then copy paste that title to where 'TypeContainerViewSegueNameHere' is written above. </p> <p><strong>EDIT 1:</strong></p> <p>A typical situation would be similar to this:</p> <pre><code>@protocol ViewControllerDelegate; @interface ViewController : UIViewController @property (nonatomic, strong) id&lt;ViewControllerDelegate&gt;delegate; @end @protocol ViewControllerDelegate &lt;NSObject&gt; - (void) delegateMethod; @end ... @implementation ViewController - (void) buttonAction:(id)sender { [self.delegate delegateMethod]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"TypeContainerViewSegueNameHere"]) { SecondViewController *viewController = (SecondViewController *)segue.destinationViewController; viewController.delegate = self; } } @end ... @interface SecondViewController : UIViewController &lt;ViewControllerDelegate&gt; @end ... @implementation SecondViewController - (void)delegateMethod { } @end </code></pre> <p>That said, you could make your main view controller the delegate of your FirstViewController, which has the two view containers as seen in your screenschot. And then call a delegate method from the main view controller to the second view controller. Although I am curious as to why you have these two view controllers as child view controllers rather than placing a view and two buttons in one view controller.</p> <p><strong>EDIT 2:</strong></p> <p>Here is an example (written quickly and not tested). Think of it as a triangle of delegates:</p> <pre><code>@protocol FirstViewControllerDelegate; @interface FirstViewController : UIViewController @property (nonatomic, strong) id&lt;FirstViewControllerDelegate&gt;delegate; @end @protocol FirstViewControllerDelegate &lt;NSObject&gt; - (void) firstViewControllerDelegateMethod; @end ... @implementation FirstViewController - (void) buttonAction:(id)sender { [self.delegate firstViewControllerDelegateMethod]; } @end ... @protocol MainViewControllerDelegate; @interface MainViewController : UIViewController &lt;FirstViewControllerDelegate&gt; @end @protocol MainViewControllerDelegate &lt;NSObject&gt; - (void) mainViewControllerDelegateMethod; @end ... @implementation MainViewController - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"TypeContainerViewSegueNameHere"]) { SecondViewController *viewController = (SecondViewController *)segue.destinationViewController; viewController.delegate = self.delegate; } if ([segue.identifier isEqualToString:@"TypeContainerViewSegueNameHere"]) { FirstViewController *viewController = (FirstViewController *)segue.destinationViewController; viewController.delegate = self; } } - (void)firstViewControllerDelegateMethod { [self.delegate mainViewControllerDelegateMethod]; } @end ... @interface SecondViewController : UIViewController &lt;MainViewControllerDelegate&gt; @end ... @implementation SecondViewController - (void)mainViewControllerDelegateMethod { } @end </code></pre> <p>Like I said, you should think about reducing the complexity of this section of your app and consider putting all of your views in one view controller.</p>
    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. 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