title: Objective C - iOS - UIWebView getting retained in ARC but Delegate methods are not being called
body: <p>I am having an issue with ARC. It is not retaining the webview. The scenario is I have to send a webview from one viewcontroller to another one. The reason is when the user searches for something I want to take him to a new screen with some other options. (I have to use the same webview)</p>
  
  <p>Here is the sample code: I have a ViewController1 which has a webview (I added it in the xib.) I am loading say google in it and once the user searches for something and when its done loading I have to take him to a new view controller and show the same webview in the new viewcontroller.  </p>
  
  <pre><code>//ViewController1
  @interface ViewController1 : UIViewController &lt;UIWebViewDelegate&gt;
      @property (nonatomic, retain) UIWebView* testWebView;
  @end
  
  @implementation ViewController1
  @synthesize testWebView;
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      testWebView = [[UIWebView alloc]init];
      testWebView.delegate = self;
      [testWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.google.com"]]];
  }
  -(void)webViewDidFinishLoad:(UIWebView *)webView{
      NSString *html = [testWebView stringByEvaluatingJavaScriptFromString: 
                        @"document.body.innerHTML"];
      if ([self.testWebView.request.url.absoluteString     rangeOfString:@"output=search"].location != NSNotFound) {
          ViewController2* newViewController = [[ViewController2 alloc] init];
          [newViewController setTestWebView:self.testWebView];
          [self.navigationController setViewControllers:[NSArray arrayWithObject:newViewController] animated:NO];
      }
  }
  - (void)dealloc{
      [self.testWebView stopLoading];
      self.testWebView.delegate = nil;
      self.testWebView = nil;
  }
  </code></pre>
  
  <p>In the second view controller I am loading stackoverflow.com after a delay of 10 secs. The problem is it is loading stackoverflow fine, but it is not calling any of the delegate methods. Why?</p>
  
  <pre><code>@interface ViewController2 : UIViewController &lt;UIWebViewDelegate&gt;
      @property (nonatomic, retain) UIWebView* testWebView;
  @end
  
  @implementation ViewController2
  @synthesize testWebView;
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      self.testWebView.delegate = self;
      [self.view addSubview:testWebView];
      [self performSelector:@selector(loadDifferentPage) withObject:nil afterDelay:10];
  }
  
  -(void)loadDifferentPage{
      [self.testWebView loadRequest:[NSURLRequest requestWithURL:[NSURL     URLWithString:@"http://www.stackoverflow.com/"]]];
  }
  
  -(void)webViewDidStartLoad:(UIWebView *)webView{
      NSLog(@"%s", __PRETTY_FUNCTION__);
  }
  
  -(void)webViewDidFinishLoad:(UIWebView *)webView{
      NSLog(@"%s", __PRETTY_FUNCTION__);
  }
  
  -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
      NSLog(@"%s", __PRETTY_FUNCTION__);
      return YES;
  }
  </code></pre>
  
  <p>ViewController2 is retaining the webview but the delegate methods are not being called. Why? </p>
  
  <p>Thanks
  Sai</p>