Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shouldn't have a subviews tell its superview much of anything. You should make the superview a delegate of your view class.</p> <pre><code>// MainView MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(...) delegate:self]; </code></pre> <p>Then save the delegate to an instance variable declared by <code>id delegate</code>. When you finish drawing:</p> <pre><code>// MyView - (void)doDrawing { drawStuff(); [delegate didFinishDrawingView:(MyView *)self] } </code></pre> <p>Now back in your MainView, implement this method</p> <pre><code>- (void)didFinishDrawingView:(MyView *)aView; </code></pre> <p>to do what you want.</p> <p>The point of all this is so that the small classes at the fringe of your app (like a small subview) shouldn't need to know how the large classes above them work. This setup allows the view to communicate up the chain, but with a message that conveys its own status instead of a message that instructs other object to do something specific. This is the way Cocoa is structured so that classes can be easily reused and their events can be repurposed however you need them to be.</p> <p>Your superview should know what to do when its subview finishes. The subview should just let people know its finished.</p> <hr> <p>Declare an instance variable in your subview class's header like this:</p> <pre><code>id delegate; </code></pre> <p>Write an initiailizer for your subview class that looks like this:</p> <pre><code>- (id)initWithFrame:(CGRect)frame delegate:(id)aDelegate { [super initWithFrame:frame]; delegate = aDelegate; return self; } </code></pre> <p>Now you have an initializer that will accept a delegate, saves that delegate, and allows you to then call methods on it.</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. 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