Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Read about <strong>delegates.</strong> Delegates are a common method to signal stuff from objects to their "parents" or any other objects.</p> <p>You should have a "delegate" property (can really be called anything, this is just a convention) on your child views. You can have buttons in your child views.</p> <p>You declare the delegate like this:</p> <pre><code>interface ChildView : UIViewController { id delegate; } @property (assign) id delegate; implementation ChildView @synthesize delegate; </code></pre> <p>Then, when you set up your child views inside your UINavigationController, you do:</p> <pre><code>ChildView *childView = [[ChildView alloc] init...] childView.delegate = self; </code></pre> <p>Inside your child view, you have a button method:</p> <pre><code>- (IBAction) didPressButton:(id)sender { [self.delegate didPressButtonToSwapView]; } </code></pre> <p>Inside your UINavigationController, you have a method:</p> <pre><code>- (void) didPressButtonToSwapView { [self popViewController]; // use the right names, I made these up :) [self pushAnotherViewController]; } </code></pre> <p>You should also read about <strong>protocols</strong> which would make the above code more robust and would help you make sure you only call the right methods on delegate, but I did not want to complicate this example.</p> <p>EDIT: yes, the cleanest way to get rid of the warning is to use a protocol. Just put this in a separate .h file:</p> <pre><code>@protocol SwitchingDelegate - (void) didPressButtonToSwapView; @end </code></pre> <p>Include this .h in the UINavController header, and say the UINavController implements the protocol:</p> <pre><code>@interface MyNav: UINavController &lt;SwitchingDelegate&gt; { ... </code></pre> <p>Implement the method in the implementation (you don't need anything more in the interface).</p> <p>In your ChildView, say that the delegate must implement the protocol: change all the declarations to:</p> <pre><code>id&lt;SwitchingDelegate&gt; delegate; </code></pre> <p>The compiler then helps you by checking whether the delegate objects really implement the protocol. You should not get any warnings when you have completed all of this correctly.</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.
    3. 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