title: iOS- protocols and delegates on the example
body: <p>Ok, i was searching but there wasn't any method that was working for me. Following code bases on many tutorials and Apple documentation, but i can't get it to work. Can anybody help please? </p>
  
  <p>Code is crashing at: obj.delegatee = self; (in class B.h), also methods respondsToSelector and performSelector:withObject aren't recogized.</p>
  
  <p>I want to set delegate object, on which there will be a method called when we tap on particular picture.</p>
  
  <p>class A.h:</p>
  
  <pre><code>@interface AViewController : UIViewController &lt;UIScrollViewDelegate&gt;{
      id delegatee;
  }
  @property (nonatomic, assign) id &lt;AViewControllerDelegate&gt; delegatee;
  @end
  
  @protocol AViewControllerDelegate
  @optional
  - (void) tappedImage:(int)tag;
  @end
  </code></pre>
  
  <p>class A.m:</p>
  
  <pre><code>@dynamic delegatee;
  - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
  UIImageView *imageView = (UIImageView *)[gestureRecognizer view];
  int a = imageView.tag;
  
  if ([self.delegatee respondsToSelector:@selector(tappedImage:)])
      [self.delegatee performSelector:@selector(tappedImage:) withObject: [NSNumber numberWithInt:a]];
  </code></pre>
  
  <p>}</p>
  
  <p>class B.h:</p>
  
  <pre><code>#import "AViewController.h"
  @interface BViewController : UIViewController &lt;AViewControllerDelegate&gt; {...}
  </code></pre>
  
  <p>class B.m:</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  //... some code
  
  AViewController *obj = [[[AViewController alloc] init] autorelease];
  obj.delegatee = self;
  }
  
  - (void) tappedImage:(int)tag{
  UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: [NSString stringWithFormat: @"%d.png",tag]]];
  CViewController *NView = [[CViewController alloc] initWithPicture: imgView.image];
  [self presentModalViewController:NView animated:YES];
  [NView release]; NView = nil;
  }
  </code></pre>
  
  <p>Many thanks for any help, i hope it will help me to understand how protocols work.</p>