title: Use Custom Delegate in AppDelegate
body: <p>i'm trying to add a Custom Delegate in App Delegate, and i'm doing it in this way:</p>
  
  <pre><code>AppDelegate.h
  
  @protocol AppDelegateDelegate &lt;NSObject&gt;
  
  - (void)finishSync:(BOOL)success;
  
  @end
  
  @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt; {
  
  @property (nonatomic, weak) id &lt;AppDelegateDelegate&gt; delegate;
  
  @end
  </code></pre>
  
  <p>Then i'm trying to use this delegate in other view connected in UITabViewController, and i do it in this way:</p>
  
  <pre><code>FirstView.h
  
  #import "AppDelegate.h"
  
  @interface FirstView : UIViewController &lt;AppDelegateDelegate&gt;
  
  @end
  
  FirstView.m
  
  @implementation FirstView
  
  ...
  
  - (void)viewDidLoad {
    AppDelegate *appController = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appController.customDelegate = self;
  
  }
  </code></pre>
  
  <p>the FirstView works perfectly, but for example if i switch in SecondViewController that have the same code to implement the delegate, the delegate don't works anymore neither in the FirstView...what i wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>i have tried the rdelmar answer, but don't work, now i'm explain better my situation, i have 4 view in a UITabBarController, this view are loaded in the didfinishloading method in app delegate, then the app open in the first view, and this is the log in view ViewDidAppear like you do in your answer:</p>
  
  <pre><code>&lt;FirstView: 0xae10280&gt;
  </code></pre>
  
  <p>then i switch in the second view and this is the viewdidappear nslog of the deleagate:</p>
  
  <pre><code>&lt;SecondView: 0x9f79b10&gt;
  </code></pre>
  
  <p>then i switch in the thirdView and this is the nslog:</p>
  
  <pre><code>&lt;ThirdView: 0xba86200&gt;
  </code></pre>
  
  <p>and the last is the FourthView:</p>
  
  <pre><code>&lt;FourtView: 0xba875b0&gt;
  </code></pre>
  
  <p>so seems that all the delegate works in all view, then i have tried to switch to the first view, and this is the log:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>i switch the third view:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>the second:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>the fourth:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>no work anymore,so i stop the application and i have run it again, and start with the firstView:</p>
  
  <pre><code>&lt;FirstView: 0xad28730&gt;
  </code></pre>
  
  <p>switch to second view:</p>
  
  <pre><code>&lt;SecondView: 0x9f682e0&gt;
  </code></pre>
  
  <p>return in the firstView:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>switch to second view:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>switch to third view:</p>
  
  <pre><code>&lt;ThirdView: 0xab297e0&gt;
  </code></pre>
  
  <p>switch to fourthView:</p>
  
  <pre><code>&lt;FourthView: 0xab28430&gt;
  </code></pre>
  
  <p>then again to the third view:</p>
  
  <pre><code>(null)
  </code></pre>
  
  <p>so as you can see the problem it's that the first time works, then when return on a view the delegate is null, any idea?</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>i have notice also that if i switch view between the NavigationController the delegate is never (null), instead switching view in UITabBarController as i do i my code give null...so it's a problem of UITabBarController views i think...</p>