title: working with UIWebViewDelegate
body: <p>I've seen a number of questions about <code>UIWebViewDelegates</code> on stackoverflow, but they've been either about something different from my problem or too over my head for me to understand (or both).</p>
  
  <p>My <code>UIWebView</code> loads fine, but I want to be able to take certain actions if the user clicks on a link within the webview once it's loaded.  In <code>viewDidLoad</code> I've set <code>self.webV.delegate = self;</code> (<code>webV</code> is the property that instantiates <code>GHWebView</code>, my <code>UIWebView</code> class).  In the view controller class I've added the following code, merely as a test before I start working on the actual method:</p>
  
  <pre><code>-(BOOL) webView:(GHWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  {
  if (navigationType==UIWebViewNavigationTypeLinkClicked)
  {
      NSLog(@"Yes!");
  }
  else
  {
      NSLog(@"No.");
  }
  return YES;
  }
  </code></pre>
  
  <p>What I'm trying to do is get "Yes!" logged if the user clicks on a link within the loaded webview.  But when the webview loads and I click on a link in it, there's no NSLog.  What should I do differently?</p>
  
  <p>(Thanks in advance for your help and for your patience with somebody who doesn't yet understand delegates....)</p>
  
  <p><strong>EDIT:</strong> Okay, here's what I think is the relevant code in GHWebView.  <em>As of now,</em> in <code>GHWebView.h</code> I declare the properties requ (<code>NSURLRequest</code>), conn (<code>NSURLConnection</code>), and urlData (<code>NSData</code>) as well as a method, <code>-(void)loadWebViewWithbaseURLString:bus withURLString:us</code>.  Then in <code>GHWebView.m</code> I define the method:</p>
  
  <pre><code>-(void)loadWebViewWithbaseURLString:bus withURLString:us
  {
  self.requ = [NSURLRequest requestWithURL:[NSURL URLWithString:us] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 20];
  self.conn=[[NSURLConnection alloc] initWithRequest:self.requ delegate:nil];
  NSError *error=nil;
  NSURLResponse *resp=nil;
  if (self.conn)
  {
      self.urlData = [NSURLConnection sendSynchronousRequest: self.requ returningResponse:&amp;resp error:&amp;error];
      NSString *htmlString = [[NSString alloc] initWithData:self.urlData encoding:NSUTF8StringEncoding];
      [self loadHTMLString:htmlString baseURL:[NSURL URLWithString:bus]];
  }
  else
  {
      UIAlertView *alert = [[UIAlertView alloc] init];
      alert.title = @"Unfortunately, I seem to be having a hard time connecting to the Internet.  Would you mind trying again later?  I'll make it worth your while, I promise.";
      [alert show];
  }
  }
  </code></pre>
  
  <p>I know that I have to declare a delegate and also add a protocol to my header file -- I think it would involve adding code like</p>
  
  <pre><code>@property (nonatomic, assign) id&lt;UIWebViewDelegate&gt; delegate;
  
  @protocol GHWebViewDelegate &lt;UIWebView&gt;
  -(void)loadWebViewWithbaseURLString:bus withURLString:us;
  @end
  </code></pre>
  
  <p>But then when I got back to the implementation file and try to replace the <code>self</code>s with <code>self.delegate</code>s in the method <code>-(void)loadWebViewWithbaseURLString:bus withURLString:us</code>, I get <code>property not found on object of type</code> errors.  What ought I to do?</p>